55from typing import Dict as _Dict , List as _List , Set as _Set , Tuple as _Tuple
66
77from pytype .rewrite .abstract import base
8+ from pytype .rewrite .abstract import internal
9+ from pytype .rewrite .abstract import utils
810
911log = logging .getLogger (__name__ )
1012
@@ -25,6 +27,19 @@ def __repr__(self):
2527 def append (self , val : _Variable ):
2628 self .constant .append (val )
2729
30+ def extend (self , val : _Variable ):
31+ try :
32+ const = utils .get_atomic_constant (val )
33+ if not isinstance (const , list ):
34+ const = None
35+ except ValueError :
36+ const = None
37+
38+ if const :
39+ self .constant .extend (const )
40+ else :
41+ self .constant .append (internal .Splat (self ._ctx , val ).to_variable ())
42+
2843
2944class Dict (base .PythonConstant [_Dict [_Variable , _Variable ]]):
3045 """Representation of a Python dict."""
@@ -34,13 +49,27 @@ def __init__(
3449 ):
3550 assert isinstance (constant , dict ), constant
3651 super ().__init__ (ctx , constant )
52+ self .indefinite = False
3753
3854 def __repr__ (self ):
3955 return f'Dict({ self .constant !r} )'
4056
4157 def setitem (self , key , val ):
4258 self .constant [key ] = val
4359
60+ def update (self , val : _Variable ):
61+ try :
62+ const = utils .get_atomic_constant (val )
63+ if not isinstance (const , dict ):
64+ const = None
65+ except ValueError :
66+ const = None
67+
68+ if const :
69+ self .constant .update (const )
70+ else :
71+ self .indefinite = True
72+
4473
4574class Set (base .PythonConstant [_Set [_Variable ]]):
4675 """Representation of a Python set."""
0 commit comments