diff --git a/mypy/stubgen.py b/mypy/stubgen.py index 1f8a1a4740f1..86f9a108f1d6 100755 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -755,6 +755,9 @@ def process_decorator(self, o: Decorator) -> None: elif fullname in DATACLASS_TRANSFORM_NAMES: p = AliasPrinter(self) self._decorators.append(f"@{decorator.accept(p)}") + elif isinstance(decorator, (NameExpr, MemberExpr)): + p = AliasPrinter(self) + self._decorators.append(f"@{decorator.accept(p)}") def get_fullname(self, expr: Expression) -> str: """Return the expression's full name.""" diff --git a/test-data/unit/stubgen.test b/test-data/unit/stubgen.test index 7700f04c6797..5c0d2d6f8e00 100644 --- a/test-data/unit/stubgen.test +++ b/test-data/unit/stubgen.test @@ -338,10 +338,24 @@ class A: ... class B(A): ... [case testDecoratedFunction] +import x + @decorator def foo(x): ... + +@x.decorator +def bar(x): ... + +@decorator(x=1, y={"a": 1}) +def foo_bar(x): ... [out] +import x + +@decorator def foo(x) -> None: ... +@x.decorator +def bar(x) -> None: ... +def foo_bar(x) -> None: ... [case testMultipleAssignment] x, y = 1, 2