Skip to content

Analyse x.__bool__() <=> bool(x) for reachabilty  #5515

@Gobot1234

Description

@Gobot1234

Is your feature request related to a problem? Please describe.
Currently objects which are marked as returning Literal[False/True] do not actually have their return types used for reachabilty analysis, there is also no way to get the return type using bool(x) which should act an alias for x.__bool__() (or maybe type(x).__bool__(x) if you'd prefer 😉)

Describe the solution you'd like
I'd like to have the return of __bool__ be used for type checking and also have bool() call the methods bool to get the return type and not just have it be bool when it could be more specific.

Additional context
MyPy is implementing a similar feature and I've found it very successful at finding bugs python/mypy#15645

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions