32
32
import itertools
33
33
import operator as operator_mod
34
34
import sys
35
- from typing import Generator , Optional
35
+ from typing import Any , Generator , List , Optional , Union
36
36
37
37
from astroid import arguments , bases , decorators , helpers , nodes , util
38
38
from astroid .const import Context
@@ -274,7 +274,12 @@ def _resolve_looppart(parts, assign_path, context):
274
274
275
275
276
276
@decorators .raise_if_nothing_inferred
277
- def for_assigned_stmts (self , node = None , context = None , assign_path = None ):
277
+ def for_assigned_stmts (
278
+ self : Union [nodes .For , nodes .Comprehension ],
279
+ node : node_classes .AssignedStmtsPossibleNode = None ,
280
+ context : Optional [InferenceContext ] = None ,
281
+ assign_path : Optional [List [int ]] = None ,
282
+ ) -> Any :
278
283
if isinstance (self , nodes .AsyncFor ) or getattr (self , "is_async" , False ):
279
284
# Skip inferring of async code for now
280
285
return dict (node = self , unknown = node , assign_path = assign_path , context = context )
@@ -291,7 +296,12 @@ def for_assigned_stmts(self, node=None, context=None, assign_path=None):
291
296
nodes .Comprehension .assigned_stmts = for_assigned_stmts
292
297
293
298
294
- def sequence_assigned_stmts (self , node = None , context = None , assign_path = None ):
299
+ def sequence_assigned_stmts (
300
+ self : Union [nodes .Tuple , nodes .List ],
301
+ node : node_classes .AssignedStmtsPossibleNode = None ,
302
+ context : Optional [InferenceContext ] = None ,
303
+ assign_path : Optional [List [int ]] = None ,
304
+ ) -> Any :
295
305
if assign_path is None :
296
306
assign_path = []
297
307
try :
@@ -314,7 +324,12 @@ def sequence_assigned_stmts(self, node=None, context=None, assign_path=None):
314
324
nodes .List .assigned_stmts = sequence_assigned_stmts
315
325
316
326
317
- def assend_assigned_stmts (self , node = None , context = None , assign_path = None ):
327
+ def assend_assigned_stmts (
328
+ self : Union [nodes .AssignName , nodes .AssignAttr ],
329
+ node : node_classes .AssignedStmtsPossibleNode = None ,
330
+ context : Optional [InferenceContext ] = None ,
331
+ assign_path : Optional [List [int ]] = None ,
332
+ ) -> Any :
318
333
return self .parent .assigned_stmts (node = self , context = context )
319
334
320
335
@@ -381,7 +396,12 @@ def _arguments_infer_argname(self, name, context):
381
396
yield util .Uninferable
382
397
383
398
384
- def arguments_assigned_stmts (self , node = None , context = None , assign_path = None ):
399
+ def arguments_assigned_stmts (
400
+ self : nodes .Arguments ,
401
+ node : node_classes .AssignedStmtsPossibleNode = None ,
402
+ context : Optional [InferenceContext ] = None ,
403
+ assign_path : Optional [List [int ]] = None ,
404
+ ) -> Any :
385
405
if context .callcontext :
386
406
callee = context .callcontext .callee
387
407
while hasattr (callee , "_proxied" ):
@@ -406,7 +426,12 @@ def arguments_assigned_stmts(self, node=None, context=None, assign_path=None):
406
426
407
427
408
428
@decorators .raise_if_nothing_inferred
409
- def assign_assigned_stmts (self , node = None , context = None , assign_path = None ):
429
+ def assign_assigned_stmts (
430
+ self : Union [nodes .AugAssign , nodes .Assign , nodes .AnnAssign ],
431
+ node : node_classes .AssignedStmtsPossibleNode = None ,
432
+ context : Optional [InferenceContext ] = None ,
433
+ assign_path : Optional [List [int ]] = None ,
434
+ ) -> Any :
410
435
if not assign_path :
411
436
yield self .value
412
437
return None
@@ -417,7 +442,12 @@ def assign_assigned_stmts(self, node=None, context=None, assign_path=None):
417
442
return dict (node = self , unknown = node , assign_path = assign_path , context = context )
418
443
419
444
420
- def assign_annassigned_stmts (self , node = None , context = None , assign_path = None ):
445
+ def assign_annassigned_stmts (
446
+ self : nodes .AnnAssign ,
447
+ node : node_classes .AssignedStmtsPossibleNode = None ,
448
+ context : Optional [InferenceContext ] = None ,
449
+ assign_path : Optional [List [int ]] = None ,
450
+ ) -> Any :
421
451
for inferred in assign_assigned_stmts (self , node , context , assign_path ):
422
452
if inferred is None :
423
453
yield util .Uninferable
@@ -471,7 +501,12 @@ def _resolve_assignment_parts(parts, assign_path, context):
471
501
472
502
473
503
@decorators .raise_if_nothing_inferred
474
- def excepthandler_assigned_stmts (self , node = None , context = None , assign_path = None ):
504
+ def excepthandler_assigned_stmts (
505
+ self : nodes .ExceptHandler ,
506
+ node : node_classes .AssignedStmtsPossibleNode = None ,
507
+ context : Optional [InferenceContext ] = None ,
508
+ assign_path : Optional [List [int ]] = None ,
509
+ ) -> Any :
475
510
for assigned in node_classes .unpack_infer (self .type ):
476
511
if isinstance (assigned , nodes .ClassDef ):
477
512
assigned = objects .ExceptionInstance (assigned )
@@ -522,7 +557,12 @@ def _infer_context_manager(self, mgr, context):
522
557
523
558
524
559
@decorators .raise_if_nothing_inferred
525
- def with_assigned_stmts (self , node = None , context = None , assign_path = None ):
560
+ def with_assigned_stmts (
561
+ self : nodes .With ,
562
+ node : node_classes .AssignedStmtsPossibleNode = None ,
563
+ context : Optional [InferenceContext ] = None ,
564
+ assign_path : Optional [List [int ]] = None ,
565
+ ) -> Any :
526
566
"""Infer names and other nodes from a *with* statement.
527
567
528
568
This enables only inference for name binding in a *with* statement.
@@ -595,7 +635,12 @@ def __enter__(self):
595
635
596
636
597
637
@decorators .raise_if_nothing_inferred
598
- def named_expr_assigned_stmts (self , node , context = None , assign_path = None ):
638
+ def named_expr_assigned_stmts (
639
+ self : nodes .NamedExpr ,
640
+ node : node_classes .AssignedStmtsPossibleNode ,
641
+ context : Optional [InferenceContext ] = None ,
642
+ assign_path : Optional [List [int ]] = None ,
643
+ ) -> Any :
599
644
"""Infer names and other nodes from an assignment expression"""
600
645
if self .target == node :
601
646
yield from self .value .infer (context = context )
@@ -612,7 +657,12 @@ def named_expr_assigned_stmts(self, node, context=None, assign_path=None):
612
657
613
658
614
659
@decorators .yes_if_nothing_inferred
615
- def starred_assigned_stmts (self , node = None , context = None , assign_path = None ):
660
+ def starred_assigned_stmts (
661
+ self : nodes .Starred ,
662
+ node : node_classes .AssignedStmtsPossibleNode = None ,
663
+ context : Optional [InferenceContext ] = None ,
664
+ assign_path : Optional [List [int ]] = None ,
665
+ ) -> Any :
616
666
"""
617
667
Arguments:
618
668
self: nodes.Starred
0 commit comments