Skip to content

Fix _thread.RLock() rejecting arguments that CPython ignores - #1269

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/rlock-new-args
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/rlock-new-args

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Description

Fixes #1258

_thread.RLock() took only cls, so any argument raised TypeError, and threading.RLock(0) raised it right after its own DeprecationWarning. CPython's rlock_new takes args and kwds and never reads them (_threadmodule.c#L1198-L1217); only threading.RLock warns, and the arguments are rejected starting in 3.15.

AS-IS

>>> _thread.RLock(0)
TypeError: RLock() takes 1 positional argument but 2 were given
>>> _thread.RLock(x=1)
TypeError: RLock() got an unexpected keyword argument 'x'

TO-BE

>>> type(_thread.RLock(0))
<class '_thread.RLock'>
>>> type(_thread.RLock(x=1))
<class '_thread.RLock'>

(matching CPython)

Changes

  • Declare RLockBuiltins.ConstructRLockNode with takesVarArgs and takesVarKeywordArgs and ignore the extra arguments, as TeeDataObjectBuiltins.TeeDataObjectNode does.
  • Add test_rlock_new_ignores_arguments to tests/test_threading.py.

Testing

mx python-jvm on darwin-aarch64, then mx graalpytest test_threading.py (6 passed, 1 skipped). test.test_threading (164 passed) and test.test_thread (26 passed) from lib-python pass. The new test fails on the unpatched build. _thread.RLock and threading.RLock with and without arguments, reentrant acquire and release, and a subclass now print the same as CPython 3.13.14.

The constructor took only cls, so _thread.RLock(0) and
threading.RLock(0) raised TypeError. CPython 3.12 and 3.13 accept and
ignore any arguments, and threading.RLock passes them on after a
DeprecationWarning that announces the removal for 3.15.

Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 31, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: _thread.RLock() rejects arguments that CPython accepts and ignores

1 participant