Skip to content

Commit 5a85ae6

Browse files
committed
threading.Lock.acquire has the timeout parameter now.
Close pylint-dev/pylint#2457
1 parent b054781 commit 5a85ae6

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ What's New in astroid 2.1.0?
66
============================
77
Release Date: TBA
88

9+
* ``threading.Lock.acquire`` has the ``timeout`` parameter now.
10+
11+
Close PyCQA/pylint#2457
12+
913
* Pass parameters by keyword name when inferring sequences.
1014

1115
Close PyCQA/pylint#2526

astroid/brain/brain_threading.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
66
# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
7-
87
import astroid
98

109

1110
def _thread_transform():
1211
return astroid.parse('''
1312
class lock(object):
14-
def acquire(self, blocking=True):
13+
def acquire(self, blocking=True, timeout=-1):
1514
pass
1615
def release(self):
1716
pass

astroid/tests/unittest_brain.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,18 @@ def test_multiprocessing_manager(self):
488488

489489
class ThreadingBrainTest(unittest.TestCase):
490490
def test_lock(self):
491-
self._test_lock_object('Lock')
491+
lock_instance = builder.extract_node("""
492+
import threading
493+
threading.Lock()
494+
""")
495+
inferred = next(lock_instance.infer())
496+
self.assert_is_valid_lock(inferred)
497+
498+
acquire_method = inferred.getattr('acquire')[0]
499+
parameters = [
500+
param.name for param in acquire_method.args.args[1:]
501+
]
502+
assert parameters == ['blocking', 'timeout']
492503

493504
def test_rlock(self):
494505
self._test_lock_object('RLock')

0 commit comments

Comments
 (0)