diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-08-17 16:19:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 16:19:07 (GMT) |
commit | 80f30cf51bd89411ef1220d714b33667d6a39901 (patch) | |
tree | 6974b70134c8f980170840d5fff76ff31594ba80 /Lib | |
parent | 0b243c2f665e6784b74ac4d602d4ee429a2ad7f0 (diff) | |
download | cpython-80f30cf51bd89411ef1220d714b33667d6a39901.zip cpython-80f30cf51bd89411ef1220d714b33667d6a39901.tar.gz cpython-80f30cf51bd89411ef1220d714b33667d6a39901.tar.bz2 |
gh-102029: Deprecate passing arguments to `_PyRLock` in `threading` (#102071)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_threading.py | 24 | ||||
-rw-r--r-- | Lib/threading.py | 7 |
2 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 4a91eef..6465a44 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -1748,6 +1748,30 @@ class PyRLockTests(lock_tests.RLockTests): class CRLockTests(lock_tests.RLockTests): locktype = staticmethod(threading._CRLock) + def test_signature(self): # gh-102029 + with warnings.catch_warnings(record=True) as warnings_log: + threading.RLock() + self.assertEqual(warnings_log, []) + + arg_types = [ + ((1,), {}), + ((), {'a': 1}), + ((1, 2), {'a': 1}), + ] + for args, kwargs in arg_types: + with self.subTest(args=args, kwargs=kwargs): + with self.assertWarns(DeprecationWarning): + threading.RLock(*args, **kwargs) + + # Subtypes with custom `__init__` are allowed (but, not recommended): + class CustomRLock(self.locktype): + def __init__(self, a, *, b) -> None: + super().__init__() + + with warnings.catch_warnings(record=True) as warnings_log: + CustomRLock(1, b=2) + self.assertEqual(warnings_log, []) + class EventTests(lock_tests.EventTests): eventtype = staticmethod(threading.Event) diff --git a/Lib/threading.py b/Lib/threading.py index e036cb8..f6bbdb0 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -4,6 +4,7 @@ import os as _os import sys as _sys import _thread import functools +import warnings from time import monotonic as _time from _weakrefset import WeakSet @@ -116,6 +117,12 @@ def RLock(*args, **kwargs): acquired it. """ + if args or kwargs: + warnings.warn( + 'Passing arguments to RLock is deprecated and will be removed in 3.15', + DeprecationWarning, + stacklevel=2, + ) if _CRLock is None: return _PyRLock(*args, **kwargs) return _CRLock(*args, **kwargs) |