File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -1457,7 +1457,15 @@ def ignore(self, node):
1457
1457
STARRED = NAMECONSTANT = NAMEDEXPR = handleChildren
1458
1458
1459
1459
def SUBSCRIPT (self , node ):
1460
- if _is_typing (node .value , 'Literal' , self .scopeStack ):
1460
+ if (
1461
+ (
1462
+ isinstance (node .value , ast .Name ) and
1463
+ node .value .id == 'Literal'
1464
+ ) or (
1465
+ isinstance (node .value , ast .Attribute ) and
1466
+ node .value .attr == 'Literal'
1467
+ )
1468
+ ):
1461
1469
orig , self ._in_typing_literal = self ._in_typing_literal , True
1462
1470
try :
1463
1471
self .handleChildren (node )
Original file line number Diff line number Diff line change @@ -507,6 +507,19 @@ def f(x: Literal['some string']) -> None:
507
507
return None
508
508
""" )
509
509
510
+ @skipIf (version_info < (3 ,), 'new in Python 3' )
511
+ def test_literal_type_some_other_module (self ):
512
+ """err on the side of false-negatives for types named Literal"""
513
+ self .flakes ("""
514
+ from my_module import compat
515
+ from my_module.compat import Literal
516
+
517
+ def f(x: compat.Literal['some string']) -> None:
518
+ return None
519
+ def g(x: Literal['some string']) -> None:
520
+ return None
521
+ """ )
522
+
510
523
@skipIf (version_info < (3 ,), 'new in Python 3' )
511
524
def test_literal_union_type_typing (self ):
512
525
self .flakes ("""
You can’t perform that action at this time.
0 commit comments