diff --git a/test/dynamo_expected_failures/CPython313-test_collections-TestChainMap.test_bool b/test/dynamo_expected_failures/CPython313-test_collections-TestChainMap.test_bool deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_collections-TestChainMap.test_constructor b/test/dynamo_expected_failures/CPython313-test_collections-TestChainMap.test_constructor deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_collections-TestChainMap.test_dict_coercion b/test/dynamo_expected_failures/CPython313-test_collections-TestChainMap.test_dict_coercion deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_collections-TestNamedTuple.test_new_builtins_issue_43102 b/test/dynamo_expected_failures/CPython313-test_collections-TestNamedTuple.test_new_builtins_issue_43102 deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_collections-TestUserObjects.test_dict_protocol b/test/dynamo_expected_failures/CPython313-test_collections-TestUserObjects.test_dict_protocol deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_collections-TestUserObjects.test_list_protocol b/test/dynamo_expected_failures/CPython313-test_collections-TestUserObjects.test_list_protocol deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_collections-TestUserObjects.test_str_protocol b/test/dynamo_expected_failures/CPython313-test_collections-TestUserObjects.test_str_protocol deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_clear b/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_clear deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_constructor b/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_constructor deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_copy b/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_copy deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_copy_noncompact b/test/dynamo_expected_failures/CPython313-test_dict-DictTest.test_copy_noncompact deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-GeneralMappingTests.test_constructor b/test/dynamo_expected_failures/CPython313-test_dict-GeneralMappingTests.test_constructor deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-GeneralMappingTests.test_read b/test/dynamo_expected_failures/CPython313-test_dict-GeneralMappingTests.test_read deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-GeneralMappingTests.test_write b/test/dynamo_expected_failures/CPython313-test_dict-GeneralMappingTests.test_write deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_dict-SubclassMappingTests.test_write b/test/dynamo_expected_failures/CPython313-test_dict-SubclassMappingTests.test_write deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_int_from_other_bases b/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_int_from_other_bases deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_power_of_two_bases_unlimited b/test/dynamo_expected_failures/CPython313-test_int-IntStrDigitLimitsTests.test_power_of_two_bases_unlimited deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonGeneralMappingTests.test_write b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonGeneralMappingTests.test_write deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonSubclassMappingTests.test_write b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CPythonSubclassMappingTests.test_write deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CSimpleLRUCacheTests.test_change_order_on_get b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CSimpleLRUCacheTests.test_change_order_on_get deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_ordered_dict-CSimpleLRUCacheTests.test_pop b/test/dynamo_expected_failures/CPython313-test_ordered_dict-CSimpleLRUCacheTests.test_pop deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_userdict-UserDictTest.test_constructor b/test/dynamo_expected_failures/CPython313-test_userdict-UserDictTest.test_constructor deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_userdict-UserDictTest.test_get b/test/dynamo_expected_failures/CPython313-test_userdict-UserDictTest.test_get deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_userdict-UserDictTest.test_len b/test/dynamo_expected_failures/CPython313-test_userdict-UserDictTest.test_len deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/dynamo_expected_failures/CPython313-test_userdict-UserDictTest.test_mutatingiteration b/test/dynamo_expected_failures/CPython313-test_userdict-UserDictTest.test_mutatingiteration deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/torch/_dynamo/polyfills/__init__.py b/torch/_dynamo/polyfills/__init__.py index 6d467b215797..07b005e736e8 100644 --- a/torch/_dynamo/polyfills/__init__.py +++ b/torch/_dynamo/polyfills/__init__.py @@ -243,6 +243,10 @@ def set_difference_update(set1, *others): set1.update(result) +def assert_dict_equal(self_, d1, d2, msg=None): + self_.assertTrue(d1 == d2, msg) + + def assert_multi_line_equal(self_, first, second, msg=None): return self_.assertTrue(first == second, msg) diff --git a/torch/_dynamo/test_case.py b/torch/_dynamo/test_case.py index 230aac4794f2..3e2d76d6e15c 100644 --- a/torch/_dynamo/test_case.py +++ b/torch/_dynamo/test_case.py @@ -140,7 +140,7 @@ class CPythonTestCase(TestCase): assertListEqual = unittest.TestCase.assertListEqual assertTupleEqual = unittest.TestCase.assertTupleEqual assertSetEqual = unittest.TestCase.assertSetEqual - assertDictEqual = unittest.TestCase.assertDictEqual + assertDictEqual = polyfills.assert_dict_equal assertRaises = unittest.TestCase.assertRaises assertRaisesRegex = unittest.TestCase.assertRaisesRegex assertWarns = unittest.TestCase.assertWarns diff --git a/torch/_dynamo/variables/builtin.py b/torch/_dynamo/variables/builtin.py index e0d722d3aae9..7376e39c9ef6 100644 --- a/torch/_dynamo/variables/builtin.py +++ b/torch/_dynamo/variables/builtin.py @@ -109,6 +109,7 @@ UnspecializedPythonVariable, ) from .user_defined import ( + MutableMappingVariable, UserDefinedDictVariable, UserDefinedObjectVariable, UserDefinedSetVariable, @@ -1865,6 +1866,12 @@ def call_cast(self, _, *args, **kwargs): hints=["Ensure your call to cast() has exactly 2 arguments."], ) + def call_dir(self, tx: "InstructionTranslator", arg): + if isinstance(arg, variables.UserDefinedClassVariable): + return VariableTracker.build(tx, dir(arg.value)) + if isinstance(arg, BuiltinVariable): + return VariableTracker.build(tx, dir(arg.fn)) + def call_dict(self, tx: "InstructionTranslator", *args, **kwargs): return BuiltinVariable.call_custom_dict(tx, dict, *args, **kwargs) @@ -2255,7 +2262,6 @@ def call_getattr( "assertRaisesRegex", "assertNotWarns", "assertWarnsRegex", - "assertDictEqual", "assertWarns", ) ): @@ -2742,6 +2748,7 @@ def call_or_(self, tx: "InstructionTranslator", a, b): ( ConstDictVariable, DictKeysVariable, + MutableMappingVariable, SetVariable, UserDefinedDictVariable, UserDefinedSetVariable, @@ -2770,7 +2777,13 @@ def call_ior(self, tx: "InstructionTranslator", a, b): # This call looks like `{"one": torch.ones(1)} |= {"two": torch.ones(2)}`. if isinstance( a, - (ConstDictVariable, DictKeysVariable, SetVariable, UserDefinedSetVariable), + ( + ConstDictVariable, + DictKeysVariable, + MutableMappingVariable, + SetVariable, + UserDefinedSetVariable, + ), ): return a.call_method(tx, "__ior__", [b], {}) diff --git a/torch/_dynamo/variables/user_defined.py b/torch/_dynamo/variables/user_defined.py index 1b6d9ffacf13..f075342ad219 100644 --- a/torch/_dynamo/variables/user_defined.py +++ b/torch/_dynamo/variables/user_defined.py @@ -91,7 +91,7 @@ tuple_methods, unpatched_nn_module_getattr, ) -from .base import AttributeMutationExisting, ValueMutationNew, VariableTracker +from .base import AttributeMutationNew, ValueMutationNew, VariableTracker from .dicts import DefaultDictVariable from .lists import SizeVariable @@ -2073,7 +2073,7 @@ class MutableMappingVariable(UserDefinedObjectVariable): def __init__(self, value, **kwargs): super().__init__(value, **kwargs) self.generic_dict_vt = variables.ConstDictVariable({}) - self.mutation_type = AttributeMutationExisting() + self.mutation_type = AttributeMutationNew() def var_getattr(self, tx: "InstructionTranslator", name: str) -> "VariableTracker": # A common pattern in the init code of MutableMapping objects is to