-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 not recognizing valid arguments to namedtuple constructor #2852
Comments
This is very closely related to #2683. |
Same with Python 3.7 Data class: @dataclass
class A:
a: int
b: float = 0.0
a = A(1, b=2.0) mypy output:
|
Dataclasses should work correctly with the most recent release. Did you upgrade? |
@JelleZijlstra thanks! Can confirm it is fixed for dataclasses in |
I'm also experiencing this with dataclasses, much like in @inoryy 's example, though when I came across it, 'b' was defined in a superclass of 'A' (also a dataclass in my case). |
@bbarker could you be more specific, and perhaps open a new issue? Relevant information includes your mypy version and the exact code you're checking and error you are getting. |
@JelleZijlstra sure, I will paste here for now. Mypy version is 0.620 Code where the error occurs: # see https://github.com/python/mypy/issues/2852 for type ignores:
self.primary_archive = Archive( # type: ignore
id=taxonomy.CATEGORIES[self.primary_category.id]['in_archive'])
self.primary_group = Group( # type: ignore
id=taxonomy.ARCHIVES[self.primary_archive.id]['in_group']) dataclass defs: @dataclass
class Category():
"""Represents an arXiv category."""
id: str = field(default_factory=str)
"""The category identifier (e.g. cs.DL)."""
name: str = field(init=False)
"""The name of the category (e.g. Digital Libraries)."""
def __post_init__(self) -> None:
"""Get the full category name."""
if self.id in taxonomy.CATEGORIES:
self.name = taxonomy.CATEGORIES[self.id]['name']
@dataclass
class Archive(Category):
"""Represents an arXiv archive."""
def __post_init__(self) -> None:
"""Get the full archive name."""
if self.id in taxonomy.ARCHIVES:
self.name = taxonomy.ARCHIVES[self.id]['name'] |
Thanks! That sounds like we're not treating inheritance between dataclasses right, which is a very separate issue from the original one here. Could you open a new issue? (I will rename this issue to clarify that it's about namedtuple.) |
This is a duplicate of #1279. |
mypy error:
Unexpected keyword argument "new_arg" for "Test"
The text was updated successfully, but these errors were encountered: