Skip to content

Commit f649e2d

Browse files
committed
Fix crash with nested attrs class (#12872)
Fixes #12868.
1 parent 64e9c0d commit f649e2d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: mypy/semanal.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4505,7 +4505,9 @@ class C:
45054505
"""
45064506
# TODO: Forward reference to name imported in class body is not
45074507
# caught.
4508-
assert self.statement # we are at class scope
4508+
if self.statement is None:
4509+
# Assume it's fine -- don't have enough context to check
4510+
return True
45094511
return (node is None
45104512
or self.is_textually_before_statement(node)
45114513
or not self.is_defined_in_current_module(node.fullname)

Diff for: test-data/unit/check-attr.test

+15
Original file line numberDiff line numberDiff line change
@@ -1734,3 +1734,18 @@ class C:
17341734
# E: Unsupported converter, only named functions and types are currently supported
17351735
)
17361736
[builtins fixtures/dict.pyi]
1737+
1738+
[case testAttrsNestedClass]
1739+
from typing import List
1740+
import attr
1741+
1742+
@attr.s
1743+
class C:
1744+
@attr.s
1745+
class D:
1746+
pass
1747+
x = attr.ib(type=List[D])
1748+
1749+
c = C(x=[C.D()])
1750+
reveal_type(c.x) # N: Revealed type is "builtins.list[__main__.C.D]"
1751+
[builtins fixtures/list.pyi]

0 commit comments

Comments
 (0)