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

Closed

Description

@asincero

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

Activity

  1. ilevkivskyi commented on Mar 4, 2019

    @ilevkivskyi
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions