diff options
author | Martin <MartinBasti@users.noreply.github.com> | 2021-11-03 22:49:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-03 22:49:04 +0100 |
commit | de307ccf20c69ef1cfba05c000de19ec2407b5cd (patch) | |
tree | 84cc363659730c3819ca9710ecf4bce6f67954a9 /tests | |
parent | be9e34722f521608a24a0d00e6991913bbad835a (diff) | |
download | pylint-git-de307ccf20c69ef1cfba05c000de19ec2407b5cd.tar.gz |
Inspection for `with threading.Lock():` (#5245)
Using `with threading.Lock():` directly has no effect.
Correct usage is:
```
lock = threading.Lock()
with lock:
...
```
This applies for:
* threading.Lock
* threading.RLock
* threading.Condition
* threading.Semaphore
* threading.BoundedSemaphore
Signed-off-by: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/u/useless/useless_with_lock.py | 58 | ||||
-rw-r--r-- | tests/functional/u/useless/useless_with_lock.txt | 11 |
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/functional/u/useless/useless_with_lock.py b/tests/functional/u/useless/useless_with_lock.py new file mode 100644 index 000000000..19d664084 --- /dev/null +++ b/tests/functional/u/useless/useless_with_lock.py @@ -0,0 +1,58 @@ +"""Tests for the useless-with-lock message""" +# pylint: disable=missing-docstring +import threading +from threading import Lock, RLock, Condition, Semaphore, BoundedSemaphore + + +with threading.Lock(): # [useless-with-lock] + ... + +with Lock(): # [useless-with-lock] + ... + +with threading.Lock() as this_shouldnt_matter: # [useless-with-lock] + ... + +with threading.RLock(): # [useless-with-lock] + ... + +with RLock(): # [useless-with-lock] + ... + +with threading.Condition(): # [useless-with-lock] + ... + +with Condition(): # [useless-with-lock] + ... + +with threading.Semaphore(): # [useless-with-lock] + ... + +with Semaphore(): # [useless-with-lock] + ... + +with threading.BoundedSemaphore(): # [useless-with-lock] + ... + +with BoundedSemaphore(): # [useless-with-lock] + ... + +lock = threading.Lock() +with lock: # this is ok + ... + +rlock = threading.RLock() +with rlock: # this is ok + ... + +cond = threading.Condition() +with cond: # this is ok + ... + +sem = threading.Semaphore() +with sem: # this is ok + ... + +b_sem = threading.BoundedSemaphore() +with b_sem: # this is ok + ... diff --git a/tests/functional/u/useless/useless_with_lock.txt b/tests/functional/u/useless/useless_with_lock.txt new file mode 100644 index 000000000..51435c35e --- /dev/null +++ b/tests/functional/u/useless/useless_with_lock.txt @@ -0,0 +1,11 @@ +useless-with-lock:7:0::'threading.Lock()' directly created in 'with' has no effect:HIGH +useless-with-lock:10:0::'threading.Lock()' directly created in 'with' has no effect:HIGH +useless-with-lock:13:0::'threading.Lock()' directly created in 'with' has no effect:HIGH +useless-with-lock:16:0::'threading.RLock()' directly created in 'with' has no effect:HIGH +useless-with-lock:19:0::'threading.RLock()' directly created in 'with' has no effect:HIGH +useless-with-lock:22:0::'threading.Condition()' directly created in 'with' has no effect:HIGH +useless-with-lock:25:0::'threading.Condition()' directly created in 'with' has no effect:HIGH +useless-with-lock:28:0::'threading.Semaphore()' directly created in 'with' has no effect:HIGH +useless-with-lock:31:0::'threading.Semaphore()' directly created in 'with' has no effect:HIGH +useless-with-lock:34:0::'threading.BoundedSemaphore()' directly created in 'with' has no effect:HIGH +useless-with-lock:37:0::'threading.BoundedSemaphore()' directly created in 'with' has no effect:HIGH |