Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from mypy.state import state
from mypy.types import (
ELLIPSIS_TYPE_NAMES,
NOT_IMPLEMENTED_TYPE_NAMES,
AnyType,
CallableType,
ExtraAttrs,
Expand Down Expand Up @@ -996,8 +997,10 @@ def is_singleton_identity_type(typ: ProperType) -> bool:
if isinstance(typ, NoneType):
return True
if isinstance(typ, Instance):
return (typ.type.is_enum and len(typ.type.enum_members) == 1) or (
typ.type.fullname in ELLIPSIS_TYPE_NAMES
return (
(typ.type.is_enum and len(typ.type.enum_members) == 1)
or (typ.type.fullname in ELLIPSIS_TYPE_NAMES)
or (typ.type.fullname in NOT_IMPLEMENTED_TYPE_NAMES)
)
if isinstance(typ, LiteralType):
return typ.is_enum_literal() or isinstance(typ.value, bool)
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/check-narrowing.test
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,14 @@ reveal_type(t.foo) # N: Revealed type is "__main__.C"
[builtins fixtures/property.pyi]

[case testNarrowingNotImplemented]
# flags: --python-version 3.10
from __future__ import annotations
import types

def foo(x: types.NotImplementedType | str):
if x is not NotImplemented:
reveal_type(x) # N: Revealed type is "builtins.str"

from typing_extensions import Self

class X:
Expand Down
2 changes: 2 additions & 0 deletions test-data/unit/lib-stub/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ if sys.version_info >= (3, 10):

class UnionType:
def __or__(self, x) -> UnionType: ...

class NotImplementedType: ...