diff --git a/mypy/semanal_newtype.py b/mypy/semanal_newtype.py index a8380309d310..16c6c024800d 100644 --- a/mypy/semanal_newtype.py +++ b/mypy/semanal_newtype.py @@ -147,7 +147,7 @@ def analyze_newtype_declaration(self, s: AssignmentStmt) -> tuple[str | None, Ca and isinstance(s.lvalues[0], NameExpr) and isinstance(s.rvalue, CallExpr) and isinstance(s.rvalue.callee, RefExpr) - and s.rvalue.callee.fullname == "typing.NewType" + and (s.rvalue.callee.fullname in ("typing.NewType", "typing_extensions.NewType")) ): name = s.lvalues[0].name diff --git a/test-data/unit/check-newtype.test b/test-data/unit/check-newtype.test index 0ff6b8396fa7..99fdf5fe7ca3 100644 --- a/test-data/unit/check-newtype.test +++ b/test-data/unit/check-newtype.test @@ -379,3 +379,10 @@ N = NewType('N', XXX) # E: Argument 2 to NewType(...) must be subclassable (got # E: Name "XXX" is not defined x: List[Union[N, int]] [builtins fixtures/list.pyi] + +[case testTypingExtensionsNewType] +# flags: --python-version 3.7 +from typing_extensions import NewType +N = NewType("N", int) +x: N +[builtins fixtures/tuple.pyi]