mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Rust: Add Callable as a base class of Function and ClosureExpr
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from typing import (
|
from typing import (
|
||||||
Callable as _Callable,
|
Callable as _Callable,
|
||||||
Dict as _Dict,
|
Dict as _Dict,
|
||||||
|
List as _List,
|
||||||
ClassVar as _ClassVar,
|
ClassVar as _ClassVar,
|
||||||
)
|
)
|
||||||
from misc.codegen.lib import schema as _schema
|
from misc.codegen.lib import schema as _schema
|
||||||
@@ -278,7 +279,7 @@ _ = _PropertyAnnotation()
|
|||||||
drop = object()
|
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]:
|
||||||
"""
|
"""
|
||||||
Add or modify schema annotations after a class has been defined previously.
|
Add or modify schema annotations after a class has been defined previously.
|
||||||
|
|
||||||
@@ -295,6 +296,8 @@ def annotate(annotated_cls: type, replace_bases: _Dict[type, type] | None = None
|
|||||||
_ClassPragma(p, value=v)(annotated_cls)
|
_ClassPragma(p, value=v)(annotated_cls)
|
||||||
if replace_bases:
|
if replace_bases:
|
||||||
annotated_cls.__bases__ = tuple(replace_bases.get(b, b) for b in annotated_cls.__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)
|
||||||
for a in dir(cls):
|
for a in dir(cls):
|
||||||
if a.startswith(_schema.inheritable_pragma_prefix):
|
if a.startswith(_schema.inheritable_pragma_prefix):
|
||||||
setattr(annotated_cls, a, getattr(cls, a))
|
setattr(annotated_cls, a, getattr(cls, a))
|
||||||
|
|||||||
@@ -1520,3 +1520,21 @@ class _:
|
|||||||
todo!()
|
todo!()
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class Callable(AstNode):
|
||||||
|
"""
|
||||||
|
A callable. Either a `Function` or a `ClosureExpr`.
|
||||||
|
"""
|
||||||
|
param_list: optional["ParamList"] | child
|
||||||
|
attrs: list["Attr"] | child
|
||||||
|
|
||||||
|
@annotate(Function, add_bases=[Callable])
|
||||||
|
class _:
|
||||||
|
param_list: drop
|
||||||
|
attrs: drop
|
||||||
|
|
||||||
|
|
||||||
|
@annotate(ClosureExpr, add_bases=[Callable])
|
||||||
|
class _:
|
||||||
|
param_list: drop
|
||||||
|
attrs: drop
|
||||||
|
|||||||
Reference in New Issue
Block a user