8000 New analyser: fix crashes when plugins encounter a placeholder node by ilevkivskyi · Pull Request #7132 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

New analyser: fix crashes when plugins encounter a placeholder node #7132

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

Merged
merged 5 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
The same for dataclasses
  • Loading branch information
ilevkivskyi committed Jul 2, 2019
commit c5fceaa0a91e3acbeae9a66c8400add5e7f1f394
4 changes: 3 additions & 1 deletion mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ def collect_attributes(self) -> List[DataclassAttribute]:
continue

node = cls.info.names[lhs.name].node
assert isinstance(node, Var)
if not isinstance(node, Var):
# This node may be not ready yet (i.e. a PlaceholderNode).
continue

# x: ClassVar[int] is ignored by dataclasses.
if node.is_classvar:
Expand Down
22 changes: 22 additions & 0 deletions test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,25 @@ a < b

class Yes: ...
[builtins fixtures/list.pyi]

[case testDataclassFieldDeferred]
from dataclasses import field, dataclass

@dataclass
class C:
x: int = field(default=func())

def func() -> int: ...
C('no') # E: Argument 1 to "C" has incompatible type "str"; expected "int"

[case testDataclassFieldDeferredFrozen]
from dataclasses import field, dataclass

@dataclass(frozen=True)
class C:
x: int = field(default=func())

def func() -> int: ...
c: C
c.x = 1 # E: Property "x" defined in "C" is read-only
[builtins fixtures/bool.pyi]
0