(self, dec: Decorator)
| 1718 | self.fail("Type signature has too many arguments", fdef, blocker=True) |
| 1719 | |
| 1720 | def visit_decorator(self, dec: Decorator) -> None: |
| 1721 | self.statement = dec |
| 1722 | # TODO: better don't modify them at all. |
| 1723 | dec.decorators = dec.original_decorators.copy() |
| 1724 | dec.func.is_conditional = self.block_depth[-1] > 0 |
| 1725 | if not dec.is_overload: |
| 1726 | self.add_symbol(dec.name, dec, dec) |
| 1727 | dec.func._fullname = self.qualified_name(dec.name) |
| 1728 | dec.var._fullname = self.qualified_name(dec.name) |
| 1729 | for d in dec.decorators: |
| 1730 | d.accept(self) |
| 1731 | removed: list[int] = [] |
| 1732 | no_type_check = False |
| 1733 | could_be_decorated_property = False |
| 1734 | for i, d in enumerate(dec.decorators): |
| 1735 | # A bunch of decorators are special cased here. |
| 1736 | if refers_to_fullname(d, "abc.abstractmethod"): |
| 1737 | removed.append(i) |
| 1738 | dec.func.abstract_status = IS_ABSTRACT |
| 1739 | self.check_decorated_function_is_method("abstractmethod", dec) |
| 1740 | elif refers_to_fullname(d, ("asyncio.coroutines.coroutine", "types.coroutine")): |
| 1741 | removed.append(i) |
| 1742 | dec.func.is_awaitable_coroutine = True |
| 1743 | elif refers_to_fullname(d, "builtins.staticmethod"): |
| 1744 | removed.append(i) |
| 1745 | dec.func.is_static = True |
| 1746 | dec.var.is_staticmethod = True |
| 1747 | self.check_decorated_function_is_method("staticmethod", dec) |
| 1748 | elif refers_to_fullname(d, "builtins.classmethod"): |
| 1749 | removed.append(i) |
| 1750 | dec.func.is_class = True |
| 1751 | dec.var.is_classmethod = True |
| 1752 | self.check_decorated_function_is_method("classmethod", dec) |
| 1753 | elif refers_to_fullname(d, OVERRIDE_DECORATOR_NAMES): |
| 1754 | removed.append(i) |
| 1755 | dec.func.is_explicit_override = True |
| 1756 | self.check_decorated_function_is_method("override", dec) |
| 1757 | elif refers_to_fullname( |
| 1758 | d, |
| 1759 | ( |
| 1760 | "builtins.property", |
| 1761 | "abc.abstractproperty", |
| 1762 | "functools.cached_property", |
| 1763 | "enum.property", |
| 1764 | "types.DynamicClassAttribute", |
| 1765 | ), |
| 1766 | ): |
| 1767 | removed.append(i) |
| 1768 | dec.func.is_property = True |
| 1769 | dec.var.is_property = True |
| 1770 | if refers_to_fullname(d, "abc.abstractproperty"): |
| 1771 | dec.func.abstract_status = IS_ABSTRACT |
| 1772 | elif refers_to_fullname(d, "functools.cached_property"): |
| 1773 | dec.var.is_settable_property = True |
| 1774 | self.check_decorated_function_is_method("property", dec) |
| 1775 | elif refers_to_fullname(d, "typing.no_type_check"): |
| 1776 | dec.var.type = AnyType(TypeOfAny.special_form) |
| 1777 | no_type_check = True |
nothing calls this directly
no test coverage detected