Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable OS specific Mypy checks #1064

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 26 additions & 31 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,35 @@ concurrency:
cancel-in-progress: true

jobs:
quality:
name: 🧑‍🏭 Quality & Docs
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip

- name: Install dependencies
run: python -m pip install tox

- name: Run linters
run: python -m tox -q -e types,lint

- name: Build the documentation
run: python -m tox -q -e docs

tox:
name: ${{ matrix.tox.name }} ${{ matrix.os.emoji }} ${{ matrix.os.name }} ${{ matrix.python }}
runs-on: ${{ matrix.os.runs-on }}
timeout-minutes: ${{ matrix.tox.timeout }}
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
tox:
- name: Types
environment: types
timeout: 15
- name: Test
environment: py
timeout: 15
os:
- name: Linux
matrix: linux
Expand All @@ -45,25 +60,6 @@ jobs:
- "3.12"
- "3.13-dev"
- "pypy-3.9"
include:
- tox:
name: Linter
environment: lint
timeout: 5
python: "3.11"
os:
name: Linux
emoji: 🐧
runs-on: [ubuntu-latest]
- tox:
name: Docs
environment: docs
timeout: 5
python: "3.11"
os:
name: Linux
emoji: 🐧
runs-on: [ubuntu-latest]
exclude:
- os:
matrix: macos
Expand All @@ -72,7 +68,6 @@ jobs:
matrix: windows
python: "pypy-3.9"


steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -83,8 +78,8 @@ jobs:
python-version: ${{ matrix.python }}
cache: pip

- name: Install test dependencies
- name: Install dependencies
run: python -m pip install tox

- name: Run ${{ matrix.tox.name }} in tox
run: python -m tox -q -e ${{ matrix.tox.environment }}
- name: Run tests
run: python -m tox -q -e py
3 changes: 2 additions & 1 deletion changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Changelog

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

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

5.0.1
~~~~~
Expand Down
8 changes: 4 additions & 4 deletions src/watchdog/observers/kqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,23 @@ def absolute_path(path: bytes | str) -> bytes | str:

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


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


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


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


class KeventDescriptorSet:
Expand Down
12 changes: 6 additions & 6 deletions src/watchdog/observers/winapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,25 @@ class OVERLAPPED(ctypes.Structure):

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


def _errcheck_handle(value: Any | None, func: Any, args: Any) -> Any:
if not value:
raise ctypes.WinError()
raise ctypes.WinError() # type: ignore[attr-defined]
if value == INVALID_HANDLE_VALUE:
raise ctypes.WinError()
raise ctypes.WinError() # type: ignore[attr-defined]
return args


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


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

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

# Handle the case when the root path is deleted
Expand Down
2 changes: 1 addition & 1 deletion src/watchdog/tricks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,4 @@ def kill_process(pid: int, stop_signal: int) -> None:
else:

def kill_process(pid: int, stop_signal: int) -> None:
os.killpg(os.getpgid(pid), stop_signal) # type: ignore[attr-defined]
os.killpg(os.getpgid(pid), stop_signal)
19 changes: 17 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,20 @@ usedevelop = true
deps =
-r requirements-tests.txt
commands =
# "--platform win32" to not fail on ctypes.windll (it does not affect the overall check on other OSes)
mypy --platform win32 docs/source/examples src
# General
python -m mypy docs/source/examples
python -m mypy src

# OS specific
python -m mypy --platform darwin --disable-error-code unused-ignore \
src/watchdog/observers/fsevents.py \
src/watchdog/observers/fsevents2.py
python -m mypy --platform freebsd --disable-error-code unused-ignore \
src/watchdog/observers/kqueue.py
python -m mypy --platform linux --disable-error-code unused-ignore \
src/watchdog/observers/inotify.py \
src/watchdog/observers/inotify_buffer.py \
src/watchdog/observers/inotify_c.py
python -m mypy --platform win32 --disable-error-code unused-ignore \
src/watchdog/observers/read_directory_changes.py \
src/watchdog/observers/winapi.py