-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#23062Milestone
Description
Summary
class X:
def __init__(self) -> None:
self.__value = 0
print('X.value:', self.__get_value())
def __get_value(self) -> int:
return self.__value
class Y(X):
def __init__(self) -> None:
super().__init__()
self.__value = 's'
print('Y.value:', self.__get_value())
def __get_value(self) -> str: # ERROR: Definition is incompatible with `X.__get_value`
return self.__value # ERROR: expected `str`, found `Unknown | Literal["s", 0]`
Y()This isn't actually an error, because the name mangling ensures that both value instances are independent:
X.value: 0
Y.value: s
This works in pyright and mypy, partially (the attribute itself still shows up as an error, seems to be python/mypy#8267).
Note that #645 does exist, but I don't really consider that to be a dupe, since it's primarily about proper name mangling (which is needed for the mentioned external access), which is a bit independent from this, e.g. pyright does not allow external access via the mangled names.
Version
a89bcfa0a
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels