A decorated function. A single Decorator object can include any number of function decorators.
| 1307 | |
| 1308 | |
| 1309 | class Decorator(SymbolNode, Statement): |
| 1310 | """A decorated function. |
| 1311 | |
| 1312 | A single Decorator object can include any number of function decorators. |
| 1313 | """ |
| 1314 | |
| 1315 | __slots__ = ("func", "decorators", "original_decorators", "var", "is_overload") |
| 1316 | |
| 1317 | __match_args__ = ("decorators", "var", "func") |
| 1318 | |
| 1319 | func: FuncDef # Decorated function |
| 1320 | decorators: list[Expression] # Decorators (may be empty) |
| 1321 | # Some decorators are removed by semanal, keep the original here. |
| 1322 | original_decorators: list[Expression] |
| 1323 | # TODO: This is mostly used for the type; consider replacing with a 'type' attribute |
| 1324 | var: Var # Represents the decorated function obj |
| 1325 | is_overload: bool |
| 1326 | |
| 1327 | def __init__(self, func: FuncDef, decorators: list[Expression], var: Var) -> None: |
| 1328 | super().__init__() |
| 1329 | self.func = func |
| 1330 | self.decorators = decorators |
| 1331 | self.original_decorators = decorators.copy() |
| 1332 | self.var = var |
| 1333 | self.is_overload = False |
| 1334 | |
| 1335 | @property |
| 1336 | def name(self) -> str: |
| 1337 | return self.func.name |
| 1338 | |
| 1339 | @property |
| 1340 | def fullname(self) -> str: |
| 1341 | return self.func.fullname |
| 1342 | |
| 1343 | @property |
| 1344 | def is_final(self) -> bool: |
| 1345 | return self.func.is_final |
| 1346 | |
| 1347 | @property |
| 1348 | def info(self) -> TypeInfo: |
| 1349 | return self.func.info |
| 1350 | |
| 1351 | @property |
| 1352 | def type(self) -> mypy.types.Type | None: |
| 1353 | return self.var.type |
| 1354 | |
| 1355 | def accept(self, visitor: StatementVisitor[T]) -> T: |
| 1356 | return visitor.visit_decorator(self) |
| 1357 | |
| 1358 | def serialize(self) -> JsonDict: |
| 1359 | return { |
| 1360 | ".class": "Decorator", |
| 1361 | "func": self.func.serialize(), |
| 1362 | "var": self.var.serialize(), |
| 1363 | "is_overload": self.is_overload, |
| 1364 | } |
| 1365 | |
| 1366 | @classmethod |
no outgoing calls
no test coverage detected
searching dependent graphs…