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

'Final' (PEP 591) shouldn't apply to '__private' symbols #9910

Closed
gvanrossum opened this issue Jan 14, 2021 · 2 comments · Fixed by #16464
Closed

'Final' (PEP 591) shouldn't apply to '__private' symbols #9910

gvanrossum opened this issue Jan 14, 2021 · 2 comments · Fixed by #16464
Labels
bug mypy got something wrong topic-final PEP 591 topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@gvanrossum
Copy link
Member

Bug Report

Since __private symbols are not shared between classes, I think we shouldn't complain if a symbol (either variable or method) that's declared Final or @final is redefined in a subclass. If you agree, we should probably add something to PEP 591 about this.

To Reproduce

from typing import Final, final

class Parent:
    __foo: Final[int] = 0

    @final
    def __bar(self) -> None:
        pass

class Child(Parent):
    __foo: Final[int] = 1  # error: Cannot override final attribute "__foo" (previously declared in base class "Parent")

    @final  # error: Cannot override final attribute "__bar" (previously declared in base class "Parent")
    def __bar(self) -> None:
        pass

Expected Behavior

No errors.

Your Environment

  • Mypy version used: 0.800+dev.37d2a5ff7a245e58af18a84e04581ccddbfb8414
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): nothing
  • Python version used: 3.9
  • Operating system and version: Windows 10
@gvanrossum gvanrossum added the bug mypy got something wrong label Jan 14, 2021
@hauntsaninja
Copy link
Collaborator

That makes sense to me. I think mypy in general is just missing mangling logic (see #9446, #8267, I also had to implement custom logic in stubtest)

@gvanrossum
Copy link
Member Author

gvanrossum commented Jan 14, 2021 via email

@AlexWaygood AlexWaygood added topic-final PEP 591 topic-runtime-semantics mypy doesn't model runtime semantics correctly labels Apr 1, 2022
ilevkivskyi added a commit that referenced this issue Nov 12, 2023
Fixes #9910
Fixes #16452

We already exclude private names from override type compatibility checks
etc., but it looks like some override checks were still performed, we
need to skip them, since private name is actually a different name in
subclass.

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
JukkaL pushed a commit that referenced this issue Nov 22, 2023
Fixes #9910
Fixes #16452

We already exclude private names from override type compatibility checks
etc., but it looks like some override checks were still performed, we
need to skip them, since private name is actually a different name in
subclass.

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-final PEP 591 topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants