Skip to content

Commit 561d5aa

Browse files
committed
fixes issue #1522237, bad init check in _threading_local
1 parent dc8c2ad commit 561d5aa

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lib/_threading_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def __new__(cls, *args, **kw):
154154
object.__setattr__(self, '_local__args', (args, kw))
155155
object.__setattr__(self, '_local__lock', RLock())
156156

157-
if args or kw and (cls.__init__ is object.__init__):
157+
if (args or kw) and (cls.__init__ is object.__init__):
158158
raise TypeError("Initialization arguments are not supported")
159159

160160
# We need to create the thread dict in anticipation of

Lib/test/test_threading_local.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ def f():
106106

107107
self.assertTrue(passed)
108108

109+
def test_arguments(self):
110+
# Issue 1522237
111+
from _thread import _local as local
112+
from _threading_local import local as py_local
113+
114+
for cls in (local, py_local):
115+
class MyLocal(cls):
116+
def __init__(self, *args, **kwargs):
117+
pass
118+
119+
MyLocal(a=1)
120+
MyLocal(1)
121+
self.assertRaises(TypeError, cls, a=1)
122+
self.assertRaises(TypeError, cls, 1)
123+
109124

110125
def test_main():
111126
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)