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

STY: Enforce ruff/flake8-pyi rules (PYI) #1355

Merged
merged 2 commits into from
Sep 23, 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
3 changes: 2 additions & 1 deletion nibabel/openers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from types import TracebackType

from _typeshed import WriteableBuffer
from typing_extensions import Self
Copy link
Member

@effigies effigies Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add this to dependencies. Should guard and import from typing for Python <3.11, and then we can use typing_extensions >=VER; python_version < '3.11'.

Ah, I see, it's in ty.TYPE_CHECKING guard. We should add to tox:

nibabel/tox.ini

Lines 172 to 186 in d1930e9

[testenv:typecheck]
description = Check type consistency
labels = check
deps =
mypy
pytest
types-setuptools
types-Pillow
pydicom
numpy
pyzstd
importlib_resources
skip_install = true
commands =
mypy nibabel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add typing_extensions.


ModeRT = ty.Literal['r', 'rt']
ModeRB = ty.Literal['rb']
Expand Down Expand Up @@ -246,7 +247,7 @@ def close_if_mine(self) -> None:
if self.me_opened:
self.close()

def __enter__(self) -> Opener:
def __enter__(self) -> Self:
return self

def __exit__(
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ select = [
"I",
"PIE",
"PLE",
"PYI",
"Q",
"RSE",
"TCH",
Expand All @@ -143,6 +144,7 @@ ignore = [
"C408",
"C416",
"PIE790",
"PYI024",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ deps =
numpy
pyzstd
importlib_resources
typing_extensions
skip_install = true
commands =
mypy nibabel
Expand Down
Loading