Skip to content

Incorrect private variables tracking #17767

Closed as not planned
Closed as not planned
@socketpair

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions