File tree 4 files changed +54
-8
lines changed 4 files changed +54
-8
lines changed Original file line number Diff line number Diff line change @@ -3689,18 +3689,20 @@ def intersect_instances(self,
3689
3689
assert isinstance (curr_module , MypyFile )
3690
3690
3691
3691
base_classes = []
3692
- formatted_names = []
3693
3692
for inst in instances :
3694
3693
expanded = [inst ]
3695
3694
if inst .type .is_intersection :
3696
3695
expanded = inst .type .bases
3697
3696
3698
3697
for expanded_inst in expanded :
3699
3698
base_classes .append (expanded_inst )
3700
- formatted_names .append (format_type_bare (expanded_inst ))
3701
3699
3700
+ # We use the pretty_names_list for error messages but can't
3701
+ # use it for the real name that goes into the symbol table
3702
+ # because it can have dots in it.
3702
3703
pretty_names_list = pretty_seq (format_type_distinctly (* base_classes , bare = True ), "and" )
3703
- short_name = '<subclass of {}>' .format (pretty_names_list )
3704
+ names_list = pretty_seq ([x .type .name for x in base_classes ], "and" )
3705
+ short_name = '<subclass of {}>' .format (names_list )
3704
3706
full_name = gen_unique_name (short_name , curr_module .names )
3705
3707
3706
3708
old_msg = self .msg
Original file line number Diff line number Diff line change @@ -5187,6 +5187,51 @@ reveal_type(Foo().x)
5187
5187
[out2]
5188
5188
tmp/b.py:2: note: Revealed type is 'a.<subclass of "A" and "B">'
5189
5189
5190
+ [case testIsInstanceAdHocIntersectionIncrementalNoChangeSameName]
5191
+ import b
5192
+ [file c.py]
5193
+ class B: pass
5194
+ [file a.py]
5195
+ import c
5196
+ class B: pass
5197
+
5198
+ class Foo:
5199
+ def __init__(self) -> None:
5200
+ x: c.B
5201
+ assert isinstance(x, B)
5202
+ self.x = x
5203
+ [file b.py]
5204
+ from a import Foo
5205
+ [file b.py.2]
5206
+ from a import Foo
5207
+ reveal_type(Foo().x)
5208
+ [builtins fixtures/isinstance.pyi]
5209
+ [out]
5210
+ [out2]
5211
+ tmp/b.py:2: note: Revealed type is 'a.<subclass of "B" and "B">'
5212
+
5213
+
5214
+ [case testIsInstanceAdHocIntersectionIncrementalNoChangeTuple]
5215
+ import b
5216
+ [file a.py]
5217
+ from typing import Tuple
5218
+ class B: pass
5219
+
5220
+ class Foo:
5221
+ def __init__(self) -> None:
5222
+ x: Tuple[int, ...]
5223
+ assert isinstance(x, B)
5224
+ self.x = x
5225
+ [file b.py]
5226
+ from a import Foo
5227
+ [file b.py.2]
5228
+ from a import Foo
5229
+ reveal_type(Foo().x)
5230
+ [builtins fixtures/isinstance.pyi]
5231
+ [out]
5232
+ [out2]
5233
+ tmp/b.py:2: note: Revealed type is 'a.<subclass of "tuple" and "B">'
5234
+
5190
5235
[case testIsInstanceAdHocIntersectionIncrementalIsInstanceChange]
5191
5236
import c
5192
5237
[file a.py]
@@ -5316,4 +5361,3 @@ reveal_type(z)
5316
5361
tmp/c.py:2: note: Revealed type is 'a.A'
5317
5362
[out2]
5318
5363
tmp/c.py:2: note: Revealed type is 'a.<subclass of "A" and "B">'
5319
-
Original file line number Diff line number Diff line change @@ -2369,14 +2369,14 @@ else:
2369
2369
2370
2370
y: A[Parent]
2371
2371
if isinstance(y, B):
2372
- reveal_type(y) # N: Revealed type is '__main__.<subclass of "A[Parent] " and "B">'
2372
+ reveal_type(y) # N: Revealed type is '__main__.<subclass of "A" and "B">'
2373
2373
reveal_type(y.f()) # N: Revealed type is '__main__.Parent*'
2374
2374
else:
2375
2375
reveal_type(y) # N: Revealed type is '__main__.A[__main__.Parent]'
2376
2376
2377
2377
z: A[Child]
2378
2378
if isinstance(z, B):
2379
- reveal_type(z) # N: Revealed type is '__main__.<subclass of "A[Child] " and "B">'
2379
+ reveal_type(z) # N: Revealed type is '__main__.<subclass of "A" and "B">1 '
2380
2380
reveal_type(z.f()) # N: Revealed type is '__main__.Child*'
2381
2381
else:
2382
2382
reveal_type(z) # N: Revealed type is '__main__.A[__main__.Child]'
@@ -2518,7 +2518,7 @@ class A: pass
2518
2518
2519
2519
x: A
2520
2520
if isinstance(x, A2):
2521
- reveal_type(x) # N: Revealed type is '__main__.<subclass of "__main__. A" and "foo. A">'
2521
+ reveal_type(x) # N: Revealed type is '__main__.<subclass of "A" and "A">'
2522
2522
2523
2523
[file foo.py]
2524
2524
class A: pass
Original file line number Diff line number Diff line change @@ -1564,7 +1564,7 @@ if isinstance(c1i, P1):
1564
1564
else:
1565
1565
reveal_type(c1i) # Unreachable
1566
1566
if isinstance(c1i, P):
1567
- reveal_type(c1i) # N: Revealed type is '__main__.<subclass of "C1[int] " and "P">'
1567
+ reveal_type(c1i) # N: Revealed type is '__main__.<subclass of "C1" and "P">'
1568
1568
else:
1569
1569
reveal_type(c1i) # N: Revealed type is '__main__.C1[builtins.int]'
1570
1570
You can’t perform that action at this time.
0 commit comments