34
34
from ..source import (
35
35
AttrSource ,
36
36
GetItemSource ,
37
- ODictGetItemSource ,
38
37
RandomValueSource ,
39
38
UnspecializedParamBufferSource ,
40
39
)
@@ -757,12 +756,7 @@ def call_method(
757
756
args : "List[VariableTracker]" ,
758
757
kwargs : "Dict[str, VariableTracker]" ,
759
758
) -> "VariableTracker" :
760
- from . import (
761
- BuiltinVariable ,
762
- ConstantVariable ,
763
- TupleVariable ,
764
- UserMethodVariable ,
765
- )
759
+ from . import ConstantVariable , UserMethodVariable
766
760
767
761
method = self ._maybe_get_baseclass_method (name )
768
762
if method is not None :
@@ -772,54 +766,6 @@ def call_method(
772
766
if is_standard_setattr (method ) or isinstance (self .value , threading .local ):
773
767
return self .method_setattr_standard (tx , * args , ** kwargs )
774
768
775
- # [NOTE] OrderedDict, dict subtypes must always have source
776
- # We cannot instantiate such subtypes in-graph due to builtin __new__
777
- if method is collections .OrderedDict .keys :
778
- # subclass of OrderedDict
779
- assert not (args or kwargs )
780
- assert self .source # OrderedDict, dict subtypes must always have source
781
- keys = list (self .value .keys ())
782
- assert all (map (ConstantVariable .is_literal , keys ))
783
- install_guard (self .source .make_guard (GuardBuilder .DICT_CONST_KEYS ))
784
- tx .output .guard_on_key_order .add (self .source .name ())
785
- return TupleVariable ([ConstantVariable .create (k ) for k in keys ])
786
-
787
- if (
788
- method in (collections .OrderedDict .__contains__ , dict .__contains__ )
789
- and len (args ) == 1
790
- and isinstance (args [0 ], (ConstantVariable , BuiltinVariable ))
791
- and inspect .getattr_static (type (self .value ), "keys" )
792
- in (collections .OrderedDict .keys , dict .keys )
793
- ):
794
- assert not kwargs
795
- assert self .source # OrderedDict, dict subtypes must always have source
796
-
797
- # TODO(anijain2305) - Why do we need to guard on all keys?
798
- install_guard (self .source .make_guard (GuardBuilder .DICT_CONST_KEYS ))
799
- return ConstantVariable .create (
800
- args [0 ].as_python_constant () in self .value
801
- )
802
-
803
- if method is collections .OrderedDict .items and isinstance (
804
- self .value , collections .OrderedDict
805
- ):
806
- assert self .source # OrderedDict, dict subtypes must always have source
807
- assert not (args or kwargs )
808
- keys = self .call_method (tx , "keys" , [], {})
809
- items = [
810
- TupleVariable (
811
- [key , self .odict_getitem (tx , key )],
812
- )
813
- for key in keys .force_unpack_var_sequence (tx )
814
- ]
815
- tx .output .guard_on_key_order .add (self .source .name ())
816
- return TupleVariable (items )
817
-
818
- if method is collections .OrderedDict .__getitem__ and len (args ) == 1 :
819
- assert not kwargs
820
- assert self .source # OrderedDict, dict subtypes must always have source
821
- return self .odict_getitem (tx , args [0 ])
822
-
823
769
if len (args ) == 1 and not kwargs :
824
770
if method is object .__eq__ :
825
771
func_var = VariableTracker .build (tx , polyfills .object_eq )
@@ -1279,23 +1225,6 @@ def call_hasattr(self, tx: "InstructionTranslator", name: str) -> "VariableTrack
1279
1225
handle_observed_exception (tx )
1280
1226
return variables .ConstantVariable .create (False )
1281
1227
1282
- def odict_getitem (self , tx : "InstructionTranslator" , key ):
1283
- from .dicts import is_hashable
1284
-
1285
- # TODO this should probably be merged with the dict handling
1286
-
1287
- index = (
1288
- key .source
1289
- if is_hashable (key ) and key .source is not None
1290
- else key .as_python_constant ()
1291
- )
1292
-
1293
- return VariableTracker .build (
1294
- tx ,
1295
- collections .OrderedDict .__getitem__ (self .value , key .as_python_constant ()),
1296
- self .source and ODictGetItemSource (self .source , index ),
1297
- )
1298
-
1299
1228
1300
1229
class FrozenDataClassVariable (UserDefinedObjectVariable ):
1301
1230
@staticmethod
0 commit comments