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

mypy confuses dataclass field name with imported function name #10640

Open
larspetrus opened this issue Jun 13, 2021 · 0 comments
Open

mypy confuses dataclass field name with imported function name #10640

larspetrus opened this issue Jun 13, 2021 · 0 comments
Labels
bug mypy got something wrong topic-dataclasses topic-runtime-semantics mypy doesn't model runtime semantics correctly topic-variable-scope

Comments

@larspetrus
Copy link

Bug Report

This standalone file produces the mistaken error models/mypy_bug.py:8: error: "str" not callable:

from dataclasses import dataclass, field
from typing import List

@dataclass
class FilterExpression:
    match_type: str
    field: str
    value: List[str] = field(default_factory=list)

This is because mypy confuses the field "field" and the imported function "field()". Renaming the field removes the error message.

Expected Behavior

This should not be an error.

It's not obvious to me what's correct here, but this code executes as intended in Python 3.8.

So either mypy or Python 3.8 is wrong about this. I choose to file the bug with mypy.

Actual Behavior

mypy gives this error:

models/mypy_bug.py:8: error: "str" not callable

Your Environment

  • Mypy version used: 0.800
  • Mypy command-line flags: Only --ignore-missing-imports [paths]
  • Mypy configuration options from mypy.ini: strict_optional = False
  • Python version used: 3.8
  • Operating system and version: MacOS 11.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-dataclasses topic-runtime-semantics mypy doesn't model runtime semantics correctly topic-variable-scope
Projects
None yet
Development

No branches or pull requests

3 participants