13
13
import sys
14
14
import typing
15
15
import warnings
16
- from typing import Dict , List , Optional , Set , TypeVar , Union , overload
16
+ from typing import TYPE_CHECKING , Dict , List , Optional , Set , TypeVar , Union , overload
17
17
18
18
from astroid import bases
19
19
from astroid import decorators as decorators_mod
58
58
59
59
from astroid .decorators import cachedproperty as cached_property
60
60
61
+ if TYPE_CHECKING :
62
+ from astroid import nodes
63
+
61
64
62
65
ITER_METHODS = ("__iter__" , "__getitem__" )
63
66
EXCEPTION_BASE_CLASSES = frozenset ({"Exception" , "BaseException" })
@@ -674,11 +677,6 @@ class GeneratorExp(ComprehensionScope):
674
677
675
678
:type: NodeNG or None
676
679
"""
677
- generators = None
678
- """The generators that are looped through.
679
-
680
- :type: list(Comprehension) or None
681
- """
682
680
683
681
def __init__ (
684
682
self ,
@@ -721,14 +719,15 @@ def __init__(
721
719
parent = parent ,
722
720
)
723
721
724
- def postinit (self , elt = None , generators = None ):
722
+ def postinit (
723
+ self , elt = None , generators : Optional [List ["nodes.Comprehension" ]] = None
724
+ ):
725
725
"""Do some setup after initialisation.
726
726
727
727
:param elt: The element that forms the output of the expression.
728
728
:type elt: NodeNG or None
729
729
730
730
:param generators: The generators that are looped through.
731
- :type generators: list(Comprehension) or None
732
731
"""
733
732
self .elt = elt
734
733
if generators is None :
@@ -772,11 +771,6 @@ class DictComp(ComprehensionScope):
772
771
773
772
:type: NodeNG or None
774
773
"""
775
- generators = None
776
- """The generators that are looped through.
777
-
778
- :type: list(Comprehension) or None
779
- """
780
774
781
775
def __init__ (
782
776
self ,
@@ -819,7 +813,12 @@ def __init__(
819
813
parent = parent ,
820
814
)
821
815
822
- def postinit (self , key = None , value = None , generators = None ):
816
+ def postinit (
817
+ self ,
818
+ key = None ,
819
+ value = None ,
820
+ generators : Optional [List ["nodes.Comprehension" ]] = None ,
821
+ ):
823
822
"""Do some setup after initialisation.
824
823
825
824
:param key: What produces the keys.
@@ -829,7 +828,6 @@ def postinit(self, key=None, value=None, generators=None):
829
828
:type value: NodeNG or None
830
829
831
830
:param generators: The generators that are looped through.
832
- :type generators: list(Comprehension) or None
833
831
"""
834
832
self .key = key
835
833
self .value = value
@@ -870,11 +868,6 @@ class SetComp(ComprehensionScope):
870
868
871
869
:type: NodeNG or None
872
870
"""
873
- generators = None
874
- """The generators that are looped through.
875
-
876
- :type: list(Comprehension) or None
877
- """
878
871
879
872
def __init__ (
880
873
self ,
@@ -917,14 +910,15 @@ def __init__(
917
910
parent = parent ,
918
911
)
919
912
920
- def postinit (self , elt = None , generators = None ):
913
+ def postinit (
914
+ self , elt = None , generators : Optional [List ["nodes.Comprehension" ]] = None
915
+ ):
921
916
"""Do some setup after initialisation.
922
917
923
918
:param elt: The element that forms the output of the expression.
924
919
:type elt: NodeNG or None
925
920
926
921
:param generators: The generators that are looped through.
927
- :type generators: list(Comprehension) or None
928
922
"""
929
923
self .elt = elt
930
924
if generators is None :
@@ -965,12 +959,6 @@ class ListComp(ComprehensionScope):
965
959
:type: NodeNG or None
966
960
"""
967
961
968
- generators = None
969
- """The generators that are looped through.
970
-
971
- :type: list(Comprehension) or None
972
- """
973
-
974
962
def __init__ (
975
963
self ,
976
964
lineno = None ,
@@ -994,7 +982,9 @@ def __init__(
994
982
parent = parent ,
995
983
)
996
984
997
- def postinit (self , elt = None , generators = None ):
985
+ def postinit (
986
+ self , elt = None , generators : Optional [List ["nodes.Comprehension" ]] = None
987
+ ):
998
988
"""Do some setup after initialisation.
999
989
1000
990
:param elt: The element that forms the output of the expression.
@@ -1004,7 +994,10 @@ def postinit(self, elt=None, generators=None):
1004
994
:type generators: list(Comprehension) or None
1005
995
"""
1006
996
self .elt = elt
1007
- self .generators = generators
997
+ if generators is None :
998
+ self .generators = []
999
+ else :
1000
+ self .generators = generators
1008
1001
1009
1002
def bool_value (self , context = None ):
1010
1003
"""Determine the boolean value of this node.
0 commit comments