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

Superclass fields incorrectly assumed to exist #2877

Closed
marcoeilers opened this issue Feb 17, 2017 · 2 comments
Closed

Superclass fields incorrectly assumed to exist #2877

marcoeilers opened this issue Feb 17, 2017 · 2 comments

Comments

@marcoeilers
Copy link

Mypy seems to always assume that classes have all fields defined in their superclass' __init__ method, even if their own __init__ never calls the superclass constructor and those fields therefore don't exist.

class A:
    def __init__(self) -> None:
        self.a = 12


class B(A):
    def __init__(self) -> None:
        self.b = 14


def m() -> int:
    ab = B()
    return ab.a + ab.b  # accepted by mypy, but fails at runtime
@ilevkivskyi
Copy link
Member

Thank you for reporting this! I think, it is an example of known behaviour: mypy does not check whether a variable was actually defined, it only checks that a variable was declared, see e.g. #2400

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 24, 2017

Closing as a duplicate of #2400.

@JukkaL JukkaL closed this as completed Feb 24, 2017
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

3 participants