| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1628,6 +1628,25 @@ class Child(Base, Mixin): | |||
| 1628 | 1628 | instance = Child(42) | |
| 1629 | 1629 | self.assertEqual(instance.a, 42) | |
| 1630 | 1630 | ||
| 1631 | + def test_do_not_shadow_user_arguments(self): | ||
| 1632 | + new_called = False | ||
| 1633 | + new_called_cls = None | ||
| 1634 | + | ||
| 1635 | + @deprecated("MyMeta will go away soon") | ||
| 1636 | + class MyMeta(type): | ||
| 1637 | + def __new__(mcs, name, bases, attrs, cls=None): | ||
| 1638 | + nonlocal new_called, new_called_cls | ||
| 1639 | + new_called = True | ||
| 1640 | + new_called_cls = cls | ||
| 1641 | + return super().__new__(mcs, name, bases, attrs) | ||
| 1642 | + | ||
| 1643 | + with self.assertWarnsRegex(DeprecationWarning, "MyMeta will go away soon"): | ||
| 1644 | + class Foo(metaclass=MyMeta, cls='haha'): | ||
| 1645 | + pass | ||
| 1646 | + | ||
| 1647 | + self.assertTrue(new_called) | ||
| 1648 | + self.assertEqual(new_called_cls, 'haha') | ||
| 1649 | + | ||
| 1631 | 1650 | def test_existing_init_subclass(self): | |
| 1632 | 1651 | @deprecated("C will go away soon") | |
| 1633 | 1652 | class C: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -589,7 +589,7 @@ def __call__(self, arg, /): | |||
| 589 | 589 | original_new = arg.__new__ | |
| 590 | 590 | ||
| 591 | 591 | @functools.wraps(original_new) | |
| 592 | - def __new__(cls, *args, **kwargs): | ||
| 592 | + def __new__(cls, /, *args, **kwargs): | ||
| 593 | 593 | if cls is arg: | |
| 594 | 594 | warn(msg, category=category, stacklevel=stacklevel + 1) | |
| 595 | 595 | if original_new is not object.__new__: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Do not shadow user arguments in generated :meth:`!__new__` by decorator :class:`warnings.deprecated`. Patch by Xuehai Pan. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments