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

Type hints: Add PYI (flake8-pyi) to Ruff and fix errors #7897

Merged
merged 8 commits into from
Mar 27, 2024

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Mar 23, 2024

Add PYI to Ruff to run the flake8-pyi linting rules related to type hints and fix the errors:

Tests/test_file_libtiff.py:246:14: PYI024 Use `typing.NamedTuple` instead of `collections.namedtuple`
Tests/test_lib_pack.py:18:18: PYI041 Use `float` instead of `int | float`
Tests/test_lib_pack.py:242:18: PYI041 Use `float` instead of `int | float`
src/PIL/PdfParser.py:85:5: PYI024 Use `typing.NamedTuple` instead of `collections.namedtuple`
src/PIL/TarIO.py:61:9: PYI034 `__enter__` methods in classes like `TarIO` usually return `self` at runtime
src/PIL/TiffTags.py:24:15: PYI024 Use `typing.NamedTuple` instead of `collections.namedtuple`
src/PIL/_imaging.pyi:1:1: PYI044 `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
src/PIL/_imagingcms.pyi:1:1: PYI044 `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
src/PIL/_imagingft.pyi:1:1: PYI044 `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
src/PIL/_imagingmath.pyi:1:1: PYI044 `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
src/PIL/_imagingmorph.pyi:1:1: PYI044 `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
src/PIL/_webp.pyi:1:1: PYI044 `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
Found 12 errors.

I skipped PYI034. The fix is to return typing.Self, but that was only added in 3.10, or typing_extensions.Self from the backport, which we're not using. Open to other solutions.

pyproject.toml Outdated Show resolved Hide resolved
src/PIL/TiffTags.py Outdated Show resolved Hide resolved
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
src/PIL/TiffTags.py Outdated Show resolved Hide resolved
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@radarhere radarhere merged commit 6ca8bfb into python-pillow:main Mar 27, 2024
57 checks passed
@hugovk hugovk deleted the flake8-pyi branch March 27, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants