Skip to content

Commit b284a2a

Browse files
committed
Rust: Add Callable as a base class of Function and ClosureExpr
1 parent 854d766 commit b284a2a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

misc/codegen/lib/schemadefs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import (
22
Callable as _Callable,
33
Dict as _Dict,
4+
List as _List,
45
ClassVar as _ClassVar,
56
)
67
from misc.codegen.lib import schema as _schema
@@ -278,7 +279,7 @@ def __or__(self, other: _schema.PropertyModifier):
278279
drop = object()
279280

280281

281-
def annotate(annotated_cls: type, replace_bases: _Dict[type, type] | None = None) -> _Callable[[type], _PropertyAnnotation]:
282+
def annotate(annotated_cls: type, add_bases: _List[type] | None = None, replace_bases: _Dict[type, type] | None = None) -> _Callable[[type], _PropertyAnnotation]:
282283
"""
283284
Add or modify schema annotations after a class has been defined previously.
284285
@@ -295,6 +296,8 @@ def decorator(cls: type) -> _PropertyAnnotation:
295296
_ClassPragma(p, value=v)(annotated_cls)
296297
if replace_bases:
297298
annotated_cls.__bases__ = tuple(replace_bases.get(b, b) for b in annotated_cls.__bases__)
299+
if add_bases:
300+
annotated_cls.__bases__ = tuple(annotated_cls.__bases__) + tuple(add_bases)
298301
for a in dir(cls):
299302
if a.startswith(_schema.inheritable_pragma_prefix):
300303
setattr(annotated_cls, a, getattr(cls, a))

rust/schema/annotations.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,3 +1520,21 @@ class _:
15201520
todo!()
15211521
```
15221522
"""
1523+
1524+
class Callable(AstNode):
1525+
"""
1526+
A callable. Either a `Function` or a `ClosureExpr`.
1527+
"""
1528+
param_list: optional["ParamList"] | child
1529+
attrs: list["Attr"] | child
1530+
1531+
@annotate(Function, add_bases=[Callable])
1532+
class _:
1533+
param_list: drop
1534+
attrs: drop
1535+
1536+
1537+
@annotate(ClosureExpr, add_bases=[Callable])
1538+
class _:
1539+
param_list: drop
1540+
attrs: drop

0 commit comments

Comments
 (0)