Skip to content

Commit 59650f8

Browse files
committed
fix: polish #1070
1 parent 29393f4 commit 59650f8

File tree

8 files changed

+32
-27
lines changed

8 files changed

+32
-27
lines changed

src/watchdog/observers/inotify_c.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def close(self) -> None:
244244
if self._waiting_to_read:
245245
# inotify_rm_watch() should write data to _inotify_fd and wake
246246
# the thread, but writing to the kill channel will gaurentee this
247-
os.write(self._kill_w, b'!')
247+
os.write(self._kill_w, b"!")
248248
else:
249249
self._close_resources()
250250

@@ -365,7 +365,7 @@ def _recursive_simulate(src_path: bytes) -> list[InotifyEvent]:
365365

366366
return event_list
367367

368-
def _close_resources(self):
368+
def _close_resources(self) -> None:
369369
os.close(self._inotify_fd)
370370
os.close(self._kill_r)
371371
os.close(self._kill_w)

src/watchdog/utils/bricks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ def _init(self, maxsize: int) -> None:
7272
super()._init(maxsize)
7373
self._last_item = None
7474

75-
def put(self, item: Any, block: bool = True, timeout: float | None = None) -> None:
75+
def put(self, item: Any, block: bool = True, timeout: float | None = None) -> None: # noqa: FBT001,FBT002
76+
"""This method will be used by `eventlet`, when enabled, so we cannot use force proper keyword-only
77+
arguments nor touch the signature. Also, the `timeout` argument will be ignored in that case.
78+
"""
7679
if self._last_item is None or item != self._last_item:
7780
super().put(item, block, timeout)
7881

tests/isolated/__init__.py

Whitespace-only changes.

tests/isolated/eventlet_observer_stops.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if __name__ == '__main__':
1+
if __name__ == "__main__":
22
import eventlet
33

44
eventlet.monkey_patch()
@@ -7,10 +7,11 @@
77
import sys
88
import tempfile
99

10-
from watchdog.observers import Observer
1110
from watchdog.events import LoggingEventHandler
11+
from watchdog.observers import Observer
1212

1313
with tempfile.TemporaryDirectory() as temp_dir:
14+
1415
def run_observer():
1516
event_handler = LoggingEventHandler()
1617
observer = Observer()
@@ -20,7 +21,7 @@ def run_observer():
2021
observer.stop()
2122

2223
def on_alarm(signum, frame):
23-
print("Observer.stop() never finished!", file=sys.stderr)
24+
print("Observer.stop() never finished!", file=sys.stderr) # noqa: T201
2425
sys.exit(1)
2526

2627
signal.signal(signal.SIGALRM, on_alarm)

tests/isolated/eventlet_skip_repeat_queue.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
if __name__ == '__main__':
1+
if __name__ == "__main__":
22
import eventlet
33

44
eventlet.monkey_patch()
55

66
from watchdog.utils.bricks import SkipRepeatsQueue
77

88
q = SkipRepeatsQueue(10)
9-
q.put('A')
10-
q.put('A')
11-
q.put('A')
12-
q.put('A')
13-
q.put('B')
14-
q.put('A')
9+
q.put("A")
10+
q.put("A")
11+
q.put("A")
12+
q.put("A")
13+
q.put("B")
14+
q.put("A")
1515

1616
value = q.get()
17-
assert value == 'A'
17+
assert value == "A"
1818
q.task_done()
1919

2020
assert q.unfinished_tasks == 2
2121

2222
value = q.get()
23-
assert value == 'B'
23+
assert value == "B"
2424
q.task_done()
2525

2626
assert q.unfinished_tasks == 1
2727

2828
value = q.get()
29-
assert value == 'A'
29+
assert value == "A"
3030
q.task_done()
3131

3232
assert q.empty()

tests/test_isolated.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import pytest
21
import importlib
32

3+
import pytest
4+
45
from watchdog.utils import platform
56

67
from .utils import run_isolated_test
@@ -10,15 +11,15 @@
1011
# Current usage ReadDirectoryChangesW on Windows is blocking, though async may be possible
1112
@pytest.mark.skipif(not platform.is_linux(), reason="Eventlet only supported in Linux")
1213
def test_observer_stops_in_eventlet():
13-
if not importlib.util.find_spec('eventlet'):
14+
if not importlib.util.find_spec("eventlet"):
1415
pytest.skip("eventlet not installed")
1516

16-
run_isolated_test('eventlet_observer_stops.py')
17+
run_isolated_test("eventlet_observer_stops.py")
1718

1819

1920
@pytest.mark.skipif(not platform.is_linux(), reason="Eventlet only supported in Linux")
2021
def test_eventlet_skip_repeat_queue():
21-
if not importlib.util.find_spec('eventlet'):
22+
if not importlib.util.find_spec("eventlet"):
2223
pytest.skip("eventlet not installed")
2324

24-
run_isolated_test('eventlet_skip_repeat_queue.py')
25+
run_isolated_test("eventlet_skip_repeat_queue.py")

tests/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ def close(self) -> None:
102102

103103

104104
def run_isolated_test(path):
105-
ISOALTED_TEST_PREFIX = os.path.join('tests', 'isolated')
106-
path = os.path.abspath(os.path.join(ISOALTED_TEST_PREFIX, path))
105+
isolated_test_prefix = os.path.join("tests", "isolated")
106+
path = os.path.abspath(os.path.join(isolated_test_prefix, path))
107107

108-
src_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'src')
108+
src_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src")
109109
new_env = os.environ.copy()
110-
new_env['PYTHONPATH'] = os.pathsep.join(sys.path + [src_dir])
110+
new_env["PYTHONPATH"] = os.pathsep.join([*sys.path, src_dir])
111111

112112
new_argv = [sys.executable, path]
113113

@@ -122,6 +122,6 @@ def run_isolated_test(path):
122122
p.communicate(timeout=timeout)
123123
except subprocess.TimeoutExpired:
124124
p.kill()
125-
assert False, 'timed out'
125+
raise
126126

127127
assert p.returncode == 0

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extras =
3333
watchmedo
3434
commands =
3535
python -m ruff format docs/source/examples src tests
36-
python -m ruff check --fix src docs/source/examples tests
36+
python -m ruff check --fix --unsafe-fixes src docs/source/examples tests
3737

3838
[testenv:types]
3939
usedevelop = true

0 commit comments

Comments
 (0)