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

Incorrect private variables tracking #17767

Open
socketpair opened this issue Sep 13, 2024 · 1 comment
Open

Incorrect private variables tracking #17767

socketpair opened this issue Sep 13, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@socketpair
Copy link

from socket import socket

class BaseBackend:
        pass
        
class SystemProcess(BaseBackend):
    def __init__(self, single_process: bool = False) -> None:
        self.__sock = socket() if single_process else None

    def _prepare(self) -> None:
        pass

class WafEventSyncer(SystemProcess):
    def __init__(self) -> None:
        super().__init__(single_process=True)
        self.__sock = socket()

    def _prepare(self) -> None:
        self.__sock.bind('something')

MyPy 1.11.2
Python 3.12

main.py:19: error: Item "None" of "socket | None" has no attribute "bind"  [union-attr]

That's wrong because these are DIFFERENT private variables.

https://mypy-play.net/?mypy=latest&python=3.12&gist=e33bf8e0176b705bfbac32a7619638df

@socketpair socketpair added the bug mypy got something wrong label Sep 13, 2024
@brianschubert
Copy link

Possible duplicate of #8267, which currently has an open PR: #16715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants