-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add threading classes, docs, and int test
- Loading branch information
1 parent
4883916
commit e440928
Showing
6 changed files
with
88 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from core_codemods.with_threading_lock import WithThreadingLock | ||
from integration_tests.base_test import ( | ||
BaseIntegrationTest, | ||
original_and_expected_from_code_path, | ||
) | ||
|
||
|
||
class TestWithThreadingLock(BaseIntegrationTest): | ||
codemod = WithThreadingLock | ||
code_path = "tests/samples/with_threading_lock.py" | ||
original_code, expected_new_code = original_and_expected_from_code_path( | ||
code_path, | ||
[ | ||
(1, "lock = threading.Lock()\n"), | ||
(2, "with lock:\n"), | ||
(4, ' print("Hello")\n'), | ||
], | ||
) | ||
expected_diff = '--- \n+++ \n@@ -1,3 +1,4 @@\n import threading\n-with threading.Lock():\n+lock = threading.Lock()\n+with lock:\n print("Hello")\n' | ||
expected_line_change = "2" | ||
change_description = WithThreadingLock.CHANGE_DESCRIPTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/core_codemods/docs/pixee_python_bad-lock-with-statement.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
This codemod separates creating a threading lock instance from calling it as a context manager. | ||
Calling `with threading.Lock()` does not have the effect you would expect. The lock is not acquired. | ||
Instead, to correctly acquire a lock, create the instance separately, before calling it as a context manager. | ||
|
||
The change will apply to any of these `threading` classes: `Lock`, `RLock`, `Condition`, `Semaphore`, and `BoundedSemaphore`. | ||
|
||
The change looks like this: | ||
|
||
```diff | ||
import threading | ||
- with threading.Lock(): | ||
+ lock = threading.Lock() | ||
+ with lock: | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import threading | ||
with threading.Lock(): | ||
print("Hello") |