| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,9 @@ | |||
| 5 | 5 | from test import shadowed_super | |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | + ADAPTIVE_WARMUP_DELAY = 2 | ||
| 9 | + | ||
| 10 | + | ||
| 8 | 11 | class A: | |
| 9 | 12 | def f(self): | |
| 10 | 13 | return 'A' | |
@@ -419,8 +422,47 @@ def test(name): | |||
| 419 | 422 | super(MyType, type(mytype)).__setattr__(mytype, "bar", 1) | |
| 420 | 423 | self.assertEqual(mytype.bar, 1) | |
| 421 | 424 | ||
| 422 | - test("foo1") | ||
| 423 | - test("foo2") | ||
| 425 | + for _ in range(ADAPTIVE_WARMUP_DELAY): | ||
| 426 | + test("foo1") | ||
| 427 | + | ||
| 428 | + def test_reassigned_new(self): | ||
| 429 | + class A: | ||
| 430 | + def __new__(cls): | ||
| 431 | + pass | ||
| 432 | + | ||
| 433 | + def __init_subclass__(cls): | ||
| 434 | + if "__new__" not in cls.__dict__: | ||
| 435 | + cls.__new__ = cls.__new__ | ||
| 436 | + | ||
| 437 | + class B(A): | ||
| 438 | + pass | ||
| 439 | + | ||
| 440 | + class C(B): | ||
| 441 | + def __new__(cls): | ||
| 442 | + return super().__new__(cls) | ||
| 443 | + | ||
| 444 | + for _ in range(ADAPTIVE_WARMUP_DELAY): | ||
| 445 | + C() | ||
| 446 | + | ||
| 447 | + def test_mixed_staticmethod_hierarchy(self): | ||
| 448 | + # This test is just a desugared version of `test_reassigned_new` | ||
| 449 | + class A: | ||
| 450 | + @staticmethod | ||
| 451 | + def some(cls, *args, **kwargs): | ||
| 452 | + self.assertFalse(args) | ||
| 453 | + self.assertFalse(kwargs) | ||
| 454 | + | ||
| 455 | + class B(A): | ||
| 456 | + def some(cls, *args, **kwargs): | ||
| 457 | + return super().some(cls, *args, **kwargs) | ||
| 458 | + | ||
| 459 | + class C(B): | ||
| 460 | + @staticmethod | ||
| 461 | + def some(cls): | ||
| 462 | + return super().some(cls) | ||
| 463 | + | ||
| 464 | + for _ in range(ADAPTIVE_WARMUP_DELAY): | ||
| 465 | + C.some(C) | ||
| 424 | 466 | ||
| 425 | 467 | ||
| 426 | 468 | if __name__ == "__main__": | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + Fix classmethod-style :func:`super` method calls (i.e., where the second | ||
| 2 | + argument to :func:`super`, or the implied second argument drawn from | ||
| 3 | + ``self/cls`` in the case of zero-arg super, is a type) when the target of | ||
| 4 | + the call is not a classmethod. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1721,7 +1721,7 @@ dummy_func( | |||
| 1721 | 1721 | PyTypeObject *cls = (PyTypeObject *)class; | |
| 1722 | 1722 | int method_found = 0; | |
| 1723 | 1723 | res2 = _PySuper_Lookup(cls, self, name, | |
| 1724 | - cls->tp_getattro == PyObject_GenericGetAttr ? &method_found : NULL); | ||
| 1724 | + Py_TYPE(self)->tp_getattro == PyObject_GenericGetAttr ? &method_found : NULL); | ||
| 1725 | 1725 | Py_DECREF(global_super); | |
| 1726 | 1726 | Py_DECREF(class); | |
| 1727 | 1727 | if (res2 == NULL) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments