Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: Add Callable as a base class of Function and ClosureExpr #17736

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion misc/codegen/lib/schemadefs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import (
Callable as _Callable,
Dict as _Dict,
List as _List,
ClassVar as _ClassVar,
)
from misc.codegen.lib import schema as _schema
Expand Down Expand Up @@ -278,7 +279,7 @@ def __or__(self, other: _schema.PropertyModifier):
drop = object()


def annotate(annotated_cls: type, replace_bases: _Dict[type, type] | None = None) -> _Callable[[type], _PropertyAnnotation]:
def annotate(annotated_cls: type, add_bases: _List[type] | None = None, replace_bases: _Dict[type, type] | None = None) -> _Callable[[type], _PropertyAnnotation]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type annotation can be typing.Iterable here.

Also, could you add a unit test in test_schemaloader.py? Should be easy copying and adapting test_annotation_replace_bases.

"""
Add or modify schema annotations after a class has been defined previously.

Expand All @@ -295,6 +296,8 @@ def decorator(cls: type) -> _PropertyAnnotation:
_ClassPragma(p, value=v)(annotated_cls)
if replace_bases:
annotated_cls.__bases__ = tuple(replace_bases.get(b, b) for b in annotated_cls.__bases__)
if add_bases:
annotated_cls.__bases__ = tuple(annotated_cls.__bases__) + tuple(add_bases)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equivalent and shorter:

Suggested change
annotated_cls.__bases__ = tuple(annotated_cls.__bases__) + tuple(add_bases)
annotated_cls.__bases__ += tuple(add_bases)

for a in dir(cls):
if a.startswith(_schema.inheritable_pragma_prefix):
setattr(annotated_cls, a, getattr(cls, a))
Expand Down
2 changes: 1 addition & 1 deletion rust/extractor/src/generated/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 67 additions & 13 deletions rust/extractor/src/generated/top.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading