mypy strict mode by jorenham · Pull Request #9410 · python-pillow/Pillow
This configures mypy to run in "strict mode", which according to mypy --help enables the following flags:
--warn-unused-configs, --disallow-any-generics, --disallow-subclassing-any, --disallow-untyped-calls, --disallow-untyped-defs, --disallow-incomplete-defs, --check-untyped-defs, --disallow-untyped-decorators, --warn-redundant-casts, --warn-unused-ignores, --warn-return-any, --no-implicit-reexport, --strict-equality,
--strict-bytes, --extra-checks
Enabling this caused a bunch of typing errors to surface, which are now also fixed.
Most of these are related to bytes/bytearray/memoryview not being assignable to each other. So I used their common denominator, collections.abc.Buffer, or rather its backport from typing_extensions (which is always available if TYPE_CHECKING because typeshed conveniently lies that it's part of the standard library).