Skip to content

mypy can't tell a "private" private attribute defined in a sub-class as being different from a same-named "private" private attribute defined in the base class. #6505

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
asincero opened this issue Mar 4, 2019 · 1 comment

Comments

@asincero
Copy link

asincero commented Mar 4, 2019

Steps to reproduce

mypy thinks the attribute defined on line 10 refers to the attribute defined on line 5:

import typing

class Base:
    def __init__(self) -> None:
        self.__private_attr: typing.Optional[int] = 69
        
class Derived(Base):
    def __init__(self) -> None:
        super().__init__()
        self.__private_attr = ''

Current behavior

mypy reports the following error:

t1.py:10: error: Incompatible types in assignment (expression has type "str", variable has type "Optional[int]")

Expected behavior

mypy shouldn't report anything.

mypy --version output

mypy 0.670

@ilevkivskyi
Copy link
Member

Duplicate of #523

This shouldn't be too hard to fix, PRs are welcome.

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