You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
private (name mangled) attributes within inherited classes can not have different types #19598
In this case both SpecialValue and BaseSpecialValue define __special_value, when run it is clear that python treats them separately as the result is:
special_value=one, base_special_value=1
Expected Behavior
No mypy error reported
Actual Behavior
However, when mypy is run the following result is returned by mypy:
mypy --config-file=default_mypy.ini mypy_dunder_test.py mypy_dunder_test.py:15: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]mypy_dunder_test.py:19: error: Incompatible return value type (got "int", expected "str") [return-value]Found 2 errors in 1 file (checked 1 source file)
Your Environment
Mypy version used: 1.17.1
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files): See below
Python version used: 3.12.0
default configuration used
# Global options:
[mypy]
warn_return_any = True
warn_unused_configs = True
Very similar to #8267 (please note that "dunder attributes" usually refer to __module__ and similar attributes that start and end with two underscores, this is just mangled/private name). Mypy indeed does not fully support name mangling, and we really should.
changed the title [-]dunder attributes within inherited classes can not have different types[/-][+]private (name mangled) attributes within inherited classes can not have different types[/+]on Aug 6, 2025
Thank you for the feedback. I agree that the terminology "dunder" was not quite right. I have updated the description and title to match the terminology used within the Python documentation Private Variables.
Activity
sterliakov commentedon Aug 6, 2025
Very similar to #8267 (please note that "dunder attributes" usually refer to
__module__and similar attributes that start and end with two underscores, this is just mangled/private name). Mypy indeed does not fully support name mangling, and we really should.[-]dunder attributes within inherited classes can not have different types[/-][+]private (name mangled) attributes within inherited classes can not have different types[/+]krcb197 commentedon Aug 6, 2025
@sterliakov
Thank you for the feedback. I agree that the terminology "dunder" was not quite right. I have updated the description and title to match the terminology used within the Python documentation Private Variables.
krcb197 commentedon Aug 6, 2025
I believe this issue was previously fixed but may have regressed, see #6505
There is even a unit test for the case, see testIgnorePrivateAttributesTypeCheck