Skip to content

Commit 2f5377a

Browse files
authored
Enable OS specific Mypy checks (#1064)
* Enable OS specific Mypy checks It would have helped to catch #1062 before the release. * ci: split & improve
1 parent 4427aa4 commit 2f5377a

File tree

6 files changed

+56
-45
lines changed

6 files changed

+56
-45
lines changed

.github/workflows/tests.yml

+26-31
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,35 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14+
quality:
15+
name: 🧑‍🏭 Quality & Docs
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.11"
25+
cache: pip
26+
27+
- name: Install dependencies
28+
run: python -m pip install tox
29+
30+
- name: Run linters
31+
run: python -m tox -q -e types,lint
32+
33+
- name: Build the documentation
34+
run: python -m tox -q -e docs
35+
1436
tox:
1537
name: ${{ matrix.tox.name }} ${{ matrix.os.emoji }} ${{ matrix.os.name }} ${{ matrix.python }}
1638
runs-on: ${{ matrix.os.runs-on }}
17-
timeout-minutes: ${{ matrix.tox.timeout }}
39+
timeout-minutes: 15
1840
strategy:
1941
fail-fast: false
2042
matrix:
21-
tox:
22-
- name: Types
23-
environment: types
24-
timeout: 15
25-
- name: Test
26-
environment: py
27-
timeout: 15
2843
os:
2944
- name: Linux
3045
matrix: linux
@@ -45,25 +60,6 @@ jobs:
4560
- "3.12"
4661
- "3.13-dev"
4762
- "pypy-3.9"
48-
include:
49-
- tox:
50-
name: Linter
51-
environment: lint
52-
timeout: 5
53-
python: "3.11"
54-
os:
55-
name: Linux
56-
emoji: 🐧
57-
runs-on: [ubuntu-latest]
58-
- tox:
59-
name: Docs
60-
environment: docs
61-
timeout: 5
62-
python: "3.11"
63-
os:
64-
name: Linux
65-
emoji: 🐧
66-
runs-on: [ubuntu-latest]
6763
exclude:
6864
- os:
6965
matrix: macos
@@ -72,7 +68,6 @@ jobs:
7268
matrix: windows
7369
python: "pypy-3.9"
7470

75-
7671
steps:
7772
- name: Checkout
7873
uses: actions/checkout@v4
@@ -83,8 +78,8 @@ jobs:
8378
python-version: ${{ matrix.python }}
8479
cache: pip
8580

86-
- name: Install test dependencies
81+
- name: Install dependencies
8782
run: python -m pip install tox
8883

89-
- name: Run ${{ matrix.tox.name }} in tox
90-
run: python -m tox -q -e ${{ matrix.tox.environment }}
84+
- name: Run tests
85+
run: python -m tox -q -e py

changelog.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ Changelog
88

99
2024-xx-xx • `full history <https://github.com/gorakhargosh/watchdog/compare/v5.0.1...HEAD>`__
1010

11+
- Enable OS specific Mypy checks (`#1064 <https://github.com/gorakhargosh/watchdog/pull/1064>`__)
1112
- [watchmedo] Fix ``tricks`` argument type of ``schedule_tricks()`` (`#1063 <https://github.com/gorakhargosh/watchdog/pull/1063>`__)
12-
- Thanks to our beloved contributors: @BoboTiG, @gnought
13+
- Thanks to our beloved contributors: @gnought, @BoboTiG
1314

1415
5.0.1
1516
~~~~~

src/watchdog/observers/kqueue.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,23 @@ def absolute_path(path: bytes | str) -> bytes | str:
121121

122122
def is_deleted(kev: select.kevent) -> bool:
123123
"""Determines whether the given kevent represents deletion."""
124-
return kev.fflags & select.KQ_NOTE_DELETE
124+
return kev.fflags & select.KQ_NOTE_DELETE > 0
125125

126126

127127
def is_modified(kev: select.kevent) -> bool:
128128
"""Determines whether the given kevent represents modification."""
129129
fflags = kev.fflags
130-
return (fflags & select.KQ_NOTE_EXTEND) or (fflags & select.KQ_NOTE_WRITE)
130+
return (fflags & select.KQ_NOTE_EXTEND > 0) or (fflags & select.KQ_NOTE_WRITE > 0)
131131

132132

133133
def is_attrib_modified(kev: select.kevent) -> bool:
134134
"""Determines whether the given kevent represents attribute modification."""
135-
return kev.fflags & select.KQ_NOTE_ATTRIB
135+
return kev.fflags & select.KQ_NOTE_ATTRIB > 0
136136

137137

138138
def is_renamed(kev: select.kevent) -> bool:
139139
"""Determines whether the given kevent represents movement."""
140-
return kev.fflags & select.KQ_NOTE_RENAME
140+
return kev.fflags & select.KQ_NOTE_RENAME > 0
141141

142142

143143
class KeventDescriptorSet:

src/watchdog/observers/winapi.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,25 @@ class OVERLAPPED(ctypes.Structure):
8383

8484
def _errcheck_bool(value: Any | None, func: Any, args: Any) -> Any:
8585
if not value:
86-
raise ctypes.WinError()
86+
raise ctypes.WinError() # type: ignore[attr-defined]
8787
return args
8888

8989

9090
def _errcheck_handle(value: Any | None, func: Any, args: Any) -> Any:
9191
if not value:
92-
raise ctypes.WinError()
92+
raise ctypes.WinError() # type: ignore[attr-defined]
9393
if value == INVALID_HANDLE_VALUE:
94-
raise ctypes.WinError()
94+
raise ctypes.WinError() # type: ignore[attr-defined]
9595
return args
9696

9797

9898
def _errcheck_dword(value: Any | None, func: Any, args: Any) -> Any:
9999
if value == 0xFFFFFFFF:
100-
raise ctypes.WinError()
100+
raise ctypes.WinError() # type: ignore[attr-defined]
101101
return args
102102

103103

104-
kernel32 = ctypes.WinDLL("kernel32")
104+
kernel32 = ctypes.WinDLL("kernel32") # type: ignore[attr-defined]
105105

106106
ReadDirectoryChangesW = kernel32.ReadDirectoryChangesW
107107
ReadDirectoryChangesW.restype = BOOL
@@ -334,7 +334,7 @@ def read_directory_changes(handle: HANDLE, path: str, *, recursive: bool) -> tup
334334
None,
335335
)
336336
except OSError as e:
337-
if e.winerror == ERROR_OPERATION_ABORTED:
337+
if e.winerror == ERROR_OPERATION_ABORTED: # type: ignore[attr-defined]
338338
return event_buffer.raw, 0
339339

340340
# Handle the case when the root path is deleted

src/watchdog/tricks/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,4 @@ def kill_process(pid: int, stop_signal: int) -> None:
287287
else:
288288

289289
def kill_process(pid: int, stop_signal: int) -> None:
290-
os.killpg(os.getpgid(pid), stop_signal) # type: ignore[attr-defined]
290+
os.killpg(os.getpgid(pid), stop_signal)

tox.ini

+17-2
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,20 @@ usedevelop = true
4040
deps =
4141
-r requirements-tests.txt
4242
commands =
43-
# "--platform win32" to not fail on ctypes.windll (it does not affect the overall check on other OSes)
44-
mypy --platform win32 docs/source/examples src
43+
# General
44+
python -m mypy docs/source/examples
45+
python -m mypy src
46+
47+
# OS specific
48+
python -m mypy --platform darwin --disable-error-code unused-ignore \
49+
src/watchdog/observers/fsevents.py \
50+
src/watchdog/observers/fsevents2.py
51+
python -m mypy --platform freebsd --disable-error-code unused-ignore \
52+
src/watchdog/observers/kqueue.py
53+
python -m mypy --platform linux --disable-error-code unused-ignore \
54+
src/watchdog/observers/inotify.py \
55+
src/watchdog/observers/inotify_buffer.py \
56+
src/watchdog/observers/inotify_c.py
57+
python -m mypy --platform win32 --disable-error-code unused-ignore \
58+
src/watchdog/observers/read_directory_changes.py \
59+
src/watchdog/observers/winapi.py

0 commit comments

Comments
 (0)