Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 23d862d

Browse filesBrowse files
hauntsaninjawesleywright
authored andcommitted
Fix isinstance with explicit (non generic) type alias (#18512)
This is a partial revert of #18173 to unblock the 1.15 release Fixes #18488
1 parent 33f60e4 commit 23d862d
Copy full SHA for 23d862d

File tree

3 files changed

+12
-21
lines changed
Filter options

3 files changed

+12
-21
lines changed

‎mypy/semanal.py

Copy file name to clipboardExpand all lines: mypy/semanal.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4022,7 +4022,6 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool:
40224022
and not res.args
40234023
and not empty_tuple_index
40244024
and not pep_695
4025-
and not pep_613
40264025
)
40274026
if isinstance(res, ProperType) and isinstance(res, Instance):
40284027
if not validate_instance(res, self.fail, empty_tuple_index):

‎test-data/unit/check-type-aliases.test

Copy file name to clipboardExpand all lines: test-data/unit/check-type-aliases.test
+11-20Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,31 +1243,22 @@ A = Union[int, List[A]]
12431243
def func(x: A) -> int: ...
12441244
[builtins fixtures/tuple.pyi]
12451245

1246-
[case testAliasExplicitNoArgsBasic]
1247-
from typing import Any, List, assert_type
1246+
[case testAliasNonGeneric]
12481247
from typing_extensions import TypeAlias
1248+
class Foo: ...
12491249

1250-
Implicit = List
1251-
Explicit: TypeAlias = List
1250+
ImplicitFoo = Foo
1251+
ExplicitFoo: TypeAlias = Foo
12521252

1253-
x1: Implicit[str]
1254-
x2: Explicit[str] # E: Bad number of arguments for type alias, expected 0, given 1
1255-
assert_type(x1, List[str])
1256-
assert_type(x2, List[Any])
1257-
[builtins fixtures/tuple.pyi]
1258-
1259-
[case testAliasExplicitNoArgsGenericClass]
1260-
# flags: --python-version 3.9
1261-
from typing import Any, assert_type
1262-
from typing_extensions import TypeAlias
1253+
x1: ImplicitFoo[str] # E: "Foo" expects no type arguments, but 1 given
1254+
x2: ExplicitFoo[str] # E: "Foo" expects no type arguments, but 1 given
12631255

1264-
Implicit = list
1265-
Explicit: TypeAlias = list
1256+
def is_foo(x: object):
1257+
if isinstance(x, ImplicitFoo):
1258+
pass
1259+
if isinstance(x, ExplicitFoo):
1260+
pass
12661261

1267-
x1: Implicit[str]
1268-
x2: Explicit[str] # E: Bad number of arguments for type alias, expected 0, given 1
1269-
assert_type(x1, list[str])
1270-
assert_type(x2, list[Any])
12711262
[builtins fixtures/tuple.pyi]
12721263

12731264
[case testAliasExplicitNoArgsTuple]

‎test-data/unit/diff.test

Copy file name to clipboardExpand all lines: test-data/unit/diff.test
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,7 @@ type H[T] = int
15631563
__main__.A
15641564
__main__.C
15651565
__main__.D
1566+
__main__.E
15661567
__main__.G
15671568
__main__.H
15681569

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.