From eb2a4ddc0643f295c3c108ce7530a24f28355942 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Sun, 18 Apr 2021 14:21:33 -0700 Subject: [PATCH 1/2] Enable some metaclass tests --- Src/IronPython/Runtime/Operations/PythonOps.cs | 3 +++ Tests/test_metaclass.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Src/IronPython/Runtime/Operations/PythonOps.cs b/Src/IronPython/Runtime/Operations/PythonOps.cs index 57c40a078..af7d92c88 100644 --- a/Src/IronPython/Runtime/Operations/PythonOps.cs +++ b/Src/IronPython/Runtime/Operations/PythonOps.cs @@ -1332,6 +1332,9 @@ public static object MakeClass(FunctionCode funcCode, Func Date: Mon, 19 Apr 2021 20:13:51 -0700 Subject: [PATCH 2/2] Remove Old/New classes --- Tests/test_metaclass.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/Tests/test_metaclass.py b/Tests/test_metaclass.py index 478877436..5364e544c 100644 --- a/Tests/test_metaclass.py +++ b/Tests/test_metaclass.py @@ -8,10 +8,7 @@ # ref: http://docs.python.org/ref/metaclasses.html -class Old: - def method(self): return 10 - -class New(object): +class SomeClass(object): def method(self): return 10 def g_f_modify(new_base=None, new_name=None): @@ -89,11 +86,11 @@ def _check(T): self.assertEqual(x.__class__.__name__, "D") for f in [ g_f_modify, g_c_modify ]: - class C(object, metaclass=f((New,), "D")): + class C(object, metaclass=f((SomeClass,), "D")): pass _check(C) - class C(metaclass=f((New,), "D")): + class C(metaclass=f((SomeClass,), "D")): pass _check(C) @@ -114,7 +111,6 @@ def method(self): return 10 self.assertEqual(x.method(), 10) try_metaclass(type) - try_metaclass(type(Old)) try_metaclass(dash_attributes) try_metaclass(sub_type1) @@ -145,23 +141,23 @@ def StartSomethingToday(self): pass self.assertTrue(hasattr(D, "start_something_today")) def test_find_metaclass(self): + # A1 hits a slightly different code path in some places than A2, same for B1, B2, etc. class A1: pass class A2(object): pass + self.assertEqual(A1.__class__, type) self.assertEqual(A2.__class__, type) - class B1(metaclass=dash_attributes): - pass - class B2(object, metaclass=dash_attributes): - pass + class B1(metaclass=dash_attributes): pass + class B2(object, metaclass=dash_attributes): pass meta = lambda *args: 100 - class D1(metaclass=meta): - pass + class D1(metaclass=meta): pass self.assertEqual(D1, 100) + self.assertEqual(D1.__class__, int) - class D2(object,metaclass=meta): - pass + class D2(object,metaclass=meta): pass + self.assertEqual(D2, 100) self.assertEqual(D2.__class__, int) # base order: how to see the effect of the order??? @@ -234,8 +230,7 @@ class C(object, metaclass=x): [], lambda name, bases, dict, extra: 1, lambda name, bases: 1, - Old, - New, + SomeClass, ]: self.assertRaises(TypeError, create, x)