Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5433,7 +5433,7 @@ def visit_with_stmt(self, s: WithStmt) -> None:
self.accept(s.body)

def check_untyped_after_decorator(self, typ: Type, func: FuncDef) -> None:
if not self.options.disallow_any_decorated or self.is_stub:
if not self.options.disallow_any_decorated or self.is_stub or self.current_node_deferred:
return

if mypy.checkexpr.has_any_type(typ):
Expand Down
32 changes: 32 additions & 0 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,38 @@ def f(x: Any) -> Any: # E: Function is untyped after decorator transformation
def h(x): # E: Function is untyped after decorator transformation
pass
[builtins fixtures/list.pyi]

[case testDisallowAnyDecoratedUnannotatedDecoratorDeferred1]
# flags: --disallow-any-decorated

def d(f):
return f

def wrapper() -> None:
if c:
@d
def h(x): # E: Function is untyped after decorator transformation
pass

c = [1]
[builtins fixtures/list.pyi]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I think the fix looks right, I don't understand the logic of the tests: shouldn't we check that there is no false positive if the decorator is precisely typed (and there is a deferral)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, thanks! Fixed


[case testDisallowAnyDecoratedUnannotatedDecoratorDeferred2]
# flags: --disallow-any-decorated

def d(f):
return f

c = 1 # no deferral - check that the previous testcase is valid

def wrapper() -> None:
if c:
@d
def h(x): # E: Function is untyped after decorator transformation
pass

[builtins fixtures/list.pyi]

[case testDisallowAnyDecoratedErrorIsReportedOnlyOnce]
# flags: --disallow-any-decorated

Expand Down
Loading