Skip to content

Commit

Permalink
Fix crash with nested attrs class (#12872)
Browse files Browse the repository at this point in the history
Fixes #12868.
  • Loading branch information
JukkaL committed May 30, 2022
1 parent 64e9c0d commit f649e2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4505,7 +4505,9 @@ class C:
"""
# TODO: Forward reference to name imported in class body is not
# caught.
assert self.statement # we are at class scope
if self.statement is None:
# Assume it's fine -- don't have enough context to check
return True
return (node is None
or self.is_textually_before_statement(node)
or not self.is_defined_in_current_module(node.fullname)
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-attr.test
Original file line number Diff line number Diff line change
Expand Up @@ -1734,3 +1734,18 @@ class C:
# E: Unsupported converter, only named functions and types are currently supported
)
[builtins fixtures/dict.pyi]

[case testAttrsNestedClass]
from typing import List
import attr

@attr.s
class C:
@attr.s
class D:
pass
x = attr.ib(type=List[D])

c = C(x=[C.D()])
reveal_type(c.x) # N: Revealed type is "builtins.list[__main__.C.D]"
[builtins fixtures/list.pyi]

0 comments on commit f649e2d

Please sign in to comment.