Skip to content

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.

Co-authored-by: Andrew Murray <[email protected]>
@radarhere radarhere merged commit 6ca8bfb into python-pillow:main Mar 27, 2024
@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.

2 participants