Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash with nested attrs class #12872

Merged
merged 1 commit into from May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion mypy/semanal.py
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
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]