-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-protocolstopic-reachabilityDetecting unreachable codeDetecting unreachable code
Description
Currently, isinstance with protocols uses the same logic as with nominal classes, i.e. only erases the type variables, but sometimes this may be not safe (as discussed in PEP 544), for example:
@runtime
class P(Protocol):
attr: int
class C:
attr = 'Hi!'
if isinstance(C(), P):
# this branch is considered unreachable by mypy, but will be executedThe idea is to perform a "deeper" erasure (setting all attribute types to Any) when considering isinstance() with protocols, thus mimicking the runtime behaviour.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-0-hightopic-protocolstopic-reachabilityDetecting unreachable codeDetecting unreachable code