Skip to content

Conversation

@kyamagu
Copy link
Contributor

@kyamagu kyamagu commented Nov 6, 2025

Summary

This PR completely eliminates all 241 mypy type checking errors in the psd_tools.psd package, improving type safety and code maintainability.

Changes

  • Removed Python 2 legacy methods: Eliminated deprecated methods like __div__, __rdiv__, __nonzero__, __long__, __coerce__, __cmp__, __oct__, and __hex__
  • Fixed _repr_pretty_ return types: Corrected methods to properly return None instead of returning string values
  • Added method signature compatibility: Added **kwargs: Any to read/write methods for BaseElement interface compatibility
  • Improved type safety: Added assertions, hasattr() checks, and appropriate type: ignore comments for unavoidable type mismatches
  • Added mixin type annotations: Provided type hints for mixin classes to properly track attributes defined in subclasses

Files Modified (12 total)

  • src/psd_tools/psd/base.py (15 errors fixed)
  • src/psd_tools/psd/filter_effects.py (7 errors fixed)
  • src/psd_tools/psd/engine_data.py (32 errors fixed)
  • src/psd_tools/psd/patterns.py (4 errors fixed)
  • src/psd_tools/psd/tagged_blocks.py (8 errors fixed)
  • src/psd_tools/psd/layer_and_mask.py (15 errors fixed)
  • src/psd_tools/psd/color.py (1 error fixed)
  • src/psd_tools/psd/vector.py (4 errors fixed)
  • src/psd_tools/psd/effects_layer.py (12 errors fixed)
  • src/psd_tools/psd/image_resources.py (23 errors fixed)
  • src/psd_tools/psd/adjustments.py (39 errors fixed)
  • src/psd_tools/psd/descriptor.py (81 errors fixed)

Test Results

  • ✅ All tests pass: 944 passed, 22 xfailed, 2 xpassed
  • ✅ Code coverage maintained at 95%
  • ✅ Mypy reports: "Success: no issues found in 17 source files"

Test plan

  • Run uv run mypy src/psd_tools/psd to verify no errors remain
  • Run uv run pytest to ensure all tests pass
  • Verify code coverage is maintained
  • Review type: ignore comments to ensure they are necessary and properly scoped

🤖 Generated with Claude Code

kyamagu and others added 5 commits November 6, 2025 23:33
Fixed type errors across 8 files in the psd_tools.psd package, reducing
mypy errors from 241 to 155. All tests pass (944 passed).

Changes by file:
- base.py (15 errors): Remove Python 2 legacy methods (__div__, __rdiv__,
  __nonzero__, __long__, __coerce__, __cmp__, __oct__, __hex__). Fix return
  statements in _repr_pretty_ methods
- filter_effects.py (7 errors): Add Optional type guards and assertions
- engine_data.py (32 errors): Add **kwargs to method signatures for
  BaseElement compatibility, add Optional type assertions
- patterns.py (4 errors): Add Optional type assertions, fix Compression
  enum usage
- tagged_blocks.py (8 errors): Add None checks for callables, fix str/bytes
  type conversions
- layer_and_mask.py (15 errors): Add type: ignore for method overrides,
  fix Optional type arithmetic
- color.py (1 error): Fix return statement in _repr_pretty_
- vector.py (4 errors): Add Optional type assertions, fix method signatures

Remaining errors (155) are in descriptor.py, adjustments.py,
image_resources.py, and effects_layer.py - mostly related to attrs
configuration with BaseElement subclasses.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add type annotations to _GlowInfo mixin class to fix attribute errors.
Add hasattr checks and type: ignore comments for write method calls.
Add assertions for Optional type safety.

Reduces total errors from 155 to 143.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add type: ignore comments for generic type compatibility issues with
ListElement/DictElement subclasses. Add **kwargs parameters to method
signatures for BaseElement interface compatibility. Add hasattr checks
before calling write methods on object types.

Key fixes:
- Generic type compatibility for list/iterable arguments
- Method signature compatibility with BaseElement interface
- Optional type safety with hasattr checks
- Fixed AlphaChannel constructor call with proper type: ignore

Reduces total errors from 143 to 120.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add type: ignore comments for attrs-generated constructor calls where
keyword arguments are not recognized by mypy. Add **kwargs parameters
to method signatures for BaseElement interface compatibility.

Key fixes:
- Constructor calls with type: ignore[call-arg] for attrs classes
- Method signatures with **kwargs for BaseElement compatibility
- Attribute access with type: ignore for object types
- Variadic argument unpacking with type: ignore

Reduces total errors from 120 to 81.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Complete mypy error fixes for psd_tools.psd package. Add type
annotations to _DescriptorMixin class, fix _repr_pretty_ return
statements, add **kwargs parameters for BaseElement compatibility,
and add type: ignore comments for attrs-generated constructors.

Key fixes:
- Added type annotations to _DescriptorMixin (name, classID)
- Fixed _repr_pretty_ methods to not return values
- Added **kwargs to all read/write method signatures
- Added type: ignore for attrs constructor calls
- Added type: ignore for Optional attribute access

Reduces total errors from 81 to 0 - ALL ERRORS FIXED!

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@kyamagu kyamagu merged commit 0b03fbc into main Nov 6, 2025
7 checks passed
@kyamagu kyamagu deleted the fix/mypy-errors-psd-package branch November 6, 2025 14:59
@kyamagu kyamagu mentioned this pull request Nov 9, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants