File tree Expand file tree Collapse file tree 2 files changed +34
-10
lines changed Expand file tree Collapse file tree 2 files changed +34
-10
lines changed Original file line number Diff line number Diff line change @@ -345,16 +345,20 @@ def _looks_like_special_alias(node: nodes.Call) -> bool:
345345    PY37: Callable = _VariadicGenericAlias(collections.abc.Callable, (), special=True) 
346346    PY39: Callable = _CallableType(collections.abc.Callable, 2) 
347347    """ 
348-     return  isinstance (node .func , nodes .Name ) and  (
349-         (
350-             node .func .name  ==  "_TupleType" 
351-             and  isinstance (node .args [0 ], nodes .Name )
352-             and  node .args [0 ].name  ==  "tuple" 
353-         )
354-         or  (
355-             node .func .name  ==  "_CallableType" 
356-             and  isinstance (node .args [0 ], nodes .Attribute )
357-             and  node .args [0 ].as_string () ==  "collections.abc.Callable" 
348+     return  (
349+         isinstance (node .func , nodes .Name )
350+         and  node .args 
351+         and  (
352+             (
353+                 node .func .name  ==  "_TupleType" 
354+                 and  isinstance (node .args [0 ], nodes .Name )
355+                 and  node .args [0 ].name  ==  "tuple" 
356+             )
357+             or  (
358+                 node .func .name  ==  "_CallableType" 
359+                 and  isinstance (node .args [0 ], nodes .Attribute )
360+                 and  node .args [0 ].as_string () ==  "collections.abc.Callable" 
361+             )
358362        )
359363    )
360364
Original file line number Diff line number Diff line change @@ -70,3 +70,23 @@ def test_infer_typing_alias_incorrect_number_of_arguments(
7070        inferred  =  next (node .value .infer ())
7171        assert  isinstance (inferred , bases .Instance )
7272        assert  inferred .name  ==  "_SpecialGenericAlias" 
73+ 
74+ 
75+ class  TestSpecialAlias :
76+     @pytest .mark .parametrize ( 
77+         "code" , 
78+         [ 
79+             "_CallableType()" , 
80+             "_TupleType()" , 
81+         ], 
82+     ) 
83+     def  test_special_alias_no_crash_on_empty_args (self , code : str ) ->  None :
84+         """ 
85+         Regression test for: https://github.com/pylint-dev/astroid/issues/2772 
86+ 
87+         Test that _CallableType() and _TupleType() calls with no arguments 
88+         do not cause an IndexError. 
89+         """ 
90+         # Should not raise IndexError 
91+         module  =  builder .parse (code )
92+         assert  isinstance (module , nodes .Module )
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments