Skip to content

Commit 80f30cf

Browse files
authored
gh-102029: Deprecate passing arguments to _PyRLock in threading (#102071)
1 parent 0b243c2 commit 80f30cf

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ Pending Removal in Python 3.15
357357
They will be removed in Python 3.15.
358358
(Contributed by Victor Stinner in :gh:`105096`.)
359359

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+
360366
Pending Removal in Python 3.16
361367
------------------------------
362368

Lib/test/test_threading.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,30 @@ class PyRLockTests(lock_tests.RLockTests):
17481748
class CRLockTests(lock_tests.RLockTests):
17491749
locktype = staticmethod(threading._CRLock)
17501750

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+
17511775
class EventTests(lock_tests.EventTests):
17521776
eventtype = staticmethod(threading.Event)
17531777

Lib/threading.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys as _sys
55
import _thread
66
import functools
7+
import warnings
78

89
from time import monotonic as _time
910
from _weakrefset import WeakSet
@@ -116,6 +117,12 @@ def RLock(*args, **kwargs):
116117
acquired it.
117118
118119
"""
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+
)
119126
if _CRLock is None:
120127
return _PyRLock(*args, **kwargs)
121128
return _CRLock(*args, **kwargs)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate passing any arguments to :func:`threading.RLock`.

0 commit comments

Comments
 (0)