Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pathlib
:meth:`~pathlib.Path.rglob`.
(Contributed by Barney Gale in :gh:`77609`.)


Optimizations
=============

Expand All @@ -120,6 +121,12 @@ Deprecated
They will be removed in Python 3.15.
(Contributed by Victor Stinner in :gh:`105096`.)

* Passing any arguments to :func:`threading.RLock` is now deprecated.
C version allows any numbers of args and kwargs,
but they are just ignored. Python version does not allow any arguments.
All arguments will be removed from :func:`threading.RLock` in Python 3.13.
(Contributed by Nikita Sobolev in :gh:`102029`.)


Removed
=======
Expand Down
22 changes: 22 additions & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,28 @@ 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__()

CustomRLock(1, b=2)

class EventTests(lock_tests.EventTests):
eventtype = staticmethod(threading.Event)

Expand Down
7 changes: 7 additions & 0 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys as _sys
import _thread
import functools
import warnings

from time import monotonic as _time
from _weakrefset import WeakSet
Expand Down Expand Up @@ -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.13',
DeprecationWarning,
stacklevel=2,
)
if _CRLock is None:
return _PyRLock(*args, **kwargs)
return _CRLock(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate passing any arguments to :func:`threading.RLock`.