-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
astral-sh/ruff
#22531Labels
bugSomething isn't workingSomething isn't workingnarrowingrelated to flow-sensitive type narrowingrelated to flow-sensitive type narrowing
Milestone
Description
Summary
def f(x: object):
if type(x) == bool:
reveal_type(x) # revealed: ~bool
else:
reveal_type(x) # revealed: ~boolWe shouldn't be doing any narrowing at all here, let alone narrowing the type to ~bool. We should narrow for constructs like if type(x) is bool or if type(x) is not bool, but it's unsafe to apply this kind of narrowing for other operators like == or != (the type of x might have a custom metaclass that allows it to compare equal to bool even though it is not bool)
Version
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingnarrowingrelated to flow-sensitive type narrowingrelated to flow-sensitive type narrowing