-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Analyse x.__bool__() <=> bool(x) for reachabilty #5515
Copy link
Copy link
Closed
Labels
as designedNot a bug, working as intendedNot a bug, working as intendedenhancement requestNew feature or requestNew feature or request
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
as designedNot a bug, working as intendedNot a bug, working as intendedenhancement requestNew feature or requestNew feature or request