Skip to content

Dataclass inheritance appears to be handled incorrectly #5384

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

Closed
bbarker opened this issue Jul 23, 2018 · 2 comments
Closed

Dataclass inheritance appears to be handled incorrectly #5384

bbarker opened this issue Jul 23, 2018 · 2 comments

Comments

@bbarker
Copy link

bbarker commented Jul 23, 2018

  • Are you reporting a bug, or opening a feature request?

Bug

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

Code where the error occurs:

        self.primary_archive = Archive(  
            id=taxonomy.CATEGORIES[self.primary_category.id]['in_archive'])
        self.primary_group = Group( 
            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']
  • What is the actual behavior/output?

I get a Unexpected keyword argument for id when trying to create instances of Abstract.

  • What is the behavior/output you expect?

No type errors.

  • What are the versions of mypy and Python you are using?

I haven't tried git master:

python = 3.6.6
mypy = 0.620

  • What are the mypy flags you are using? (For example --strict-optional)

mypy.ini:

[mypy]
#mypy_path = $MYPYPATH

#
# Covered by --strict, with some turned off:
#
disallow_untyped_calls=True
disallow_untyped_defs=True
check_untyped_defs=True
# currently an issue with sql alchemy
disallow_subclassing_any=false
# Need to experiment/think about this one:
disallow_any_decorated=false
warn_redundant_casts=True
warn_return_any=True
warn_unused_ignores=True
# this seems to be at least somewhat non-functioning:
warn_unused_configs=True
#may be worth reconsidering this one:
no_implicit_optional=True
strict_optional=True

#
# Other: 
#
ignore_missing_imports=True


[mypy-sqlalchemy.*]
disallow_untyped_calls=False
disallow_untyped_defs=False

Note: originally reported in #2852

@bbarker
Copy link
Author

bbarker commented Jul 23, 2018

cc @JelleZijlstra

@ilevkivskyi
Copy link
Member

I cannot reproduce this, but my guess is that you are using ignore_missing_imports=True together with Python 3.6, so this is probably just a duplicate of #5389. Could you please try running with --python-version=3.7 (and --no-site-packages if needed)? And reopen if you find a repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants