| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -357,6 +357,12 @@ Pending Removal in Python 3.15 | |||
| 357 | 357 | They will be removed in Python 3.15. | |
| 358 | 358 | (Contributed by Victor Stinner in :gh:`105096`.) | |
| 359 | 359 | ||
| 360 | + * Passing any arguments to :func:`threading.RLock` is now deprecated. | ||
| 361 | + C version allows any numbers of args and kwargs, | ||
| 362 | + but they are just ignored. Python version does not allow any arguments. | ||
| 363 | + All arguments will be removed from :func:`threading.RLock` in Python 3.15. | ||
| 364 | + (Contributed by Nikita Sobolev in :gh:`102029`.) | ||
| 365 | + | ||
| 360 | 366 | Pending Removal in Python 3.16 | |
| 361 | 367 | ------------------------------ | |
| 362 | 368 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1748,6 +1748,30 @@ class PyRLockTests(lock_tests.RLockTests): | |||
| 1748 | 1748 | class CRLockTests(lock_tests.RLockTests): | |
| 1749 | 1749 | locktype = staticmethod(threading._CRLock) | |
| 1750 | 1750 | ||
| 1751 | + def test_signature(self): # gh-102029 | ||
| 1752 | + with warnings.catch_warnings(record=True) as warnings_log: | ||
| 1753 | + threading.RLock() | ||
| 1754 | + self.assertEqual(warnings_log, []) | ||
| 1755 | + | ||
| 1756 | + arg_types = [ | ||
| 1757 | + ((1,), {}), | ||
| 1758 | + ((), {'a': 1}), | ||
| 1759 | + ((1, 2), {'a': 1}), | ||
| 1760 | + ] | ||
| 1761 | + for args, kwargs in arg_types: | ||
| 1762 | + with self.subTest(args=args, kwargs=kwargs): | ||
| 1763 | + with self.assertWarns(DeprecationWarning): | ||
| 1764 | + threading.RLock(*args, **kwargs) | ||
| 1765 | + | ||
| 1766 | + # Subtypes with custom `__init__` are allowed (but, not recommended): | ||
| 1767 | + class CustomRLock(self.locktype): | ||
| 1768 | + def __init__(self, a, *, b) -> None: | ||
| 1769 | + super().__init__() | ||
| 1770 | + | ||
| 1771 | + with warnings.catch_warnings(record=True) as warnings_log: | ||
| 1772 | + CustomRLock(1, b=2) | ||
| 1773 | + self.assertEqual(warnings_log, []) | ||
| 1774 | + | ||
| 1751 | 1775 | class EventTests(lock_tests.EventTests): | |
| 1752 | 1776 | eventtype = staticmethod(threading.Event) | |
| 1753 | 1777 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | import sys as _sys | |
| 5 | 5 | import _thread | |
| 6 | 6 | import functools | |
| 7 | + import warnings | ||
| 7 | 8 | ||
| 8 | 9 | from time import monotonic as _time | |
| 9 | 10 | from _weakrefset import WeakSet | |
@@ -116,6 +117,12 @@ def RLock(*args, **kwargs): | |||
| 116 | 117 | acquired it. | |
| 117 | 118 | ||
| 118 | 119 | """ | |
| 120 | + if args or kwargs: | ||
| 121 | + warnings.warn( | ||
| 122 | + 'Passing arguments to RLock is deprecated and will be removed in 3.15', | ||
| 123 | + DeprecationWarning, | ||
| 124 | + stacklevel=2, | ||
| 125 | + ) | ||
| 119 | 126 | if _CRLock is None: | |
| 120 | 127 | return _PyRLock(*args, **kwargs) | |
| 121 | 128 | return _CRLock(*args, **kwargs) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Deprecate passing any arguments to :func:`threading.RLock`. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments