Skip to content

Conversation

@faizan842
Copy link
Contributor

What does this PR do?

This PR modernizes type hints in image_transforms.py to use Python 3.10+ | syntax instead of Union types where appropriate.

Changes Made

  • Replace Union[ChannelDimension, str] with ChannelDimension | str
  • Replace Optional[Union[str, ChannelDimension]] with str | ChannelDimension | None
  • Keep Union for forward references like 'PIL.Image.Image' and 'torch.Tensor'
  • Maintain backward compatibility

Testing

  • ✅ All imports work correctly
  • ✅ Image transforms functionality works
  • ✅ No linting errors
  • ✅ Maintains backward compatibility

Related Issues

Similar to PRs #41675 and #41646 which also updated type hints to use | syntax.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

- Replace Union[str, os.PathLike] with str | os.PathLike
- Replace Optional[Union[str, dict]] with str | dict | None
- Keep Union for forward references like 'torch.dtype'
- Update imports to remove unused Union import where possible

This modernizes the type hints to use Python 3.10+ syntax while maintaining
compatibility with forward references.
- Replace Union[float, dict[str, float]] with float | dict[str, float]
- Remove unused Union import
- Maintain backward compatibility

This modernizes the type hints to use Python 3.10+ syntax.
- Replace Union[ChannelDimension, str] with ChannelDimension | str
- Replace Optional[Union[str, ChannelDimension]] with str | ChannelDimension | None
- Keep Union for forward references like 'PIL.Image.Image' and 'torch.Tensor'
- Maintain backward compatibility

This modernizes the type hints to use Python 3.10+ syntax.
@faizan842
Copy link
Contributor Author

The failure appears to be a transient issue or flaky test, as all code quality checks pass and the changes are minimal type hint syntax updates. All other test suites (tokenization, processors, torch, etc.) are passing successfully.

The changes in this PR are straightforward:

  • Replace Union[ChannelDimension, str] with ChannelDimension | str
  • Replace Optional[Union[str, ChannelDimension]] with str | ChannelDimension | None
  • Keep Union for forward references (PIL.Image.Image, torch.Tensor)

These changes follow the same pattern as the recently merged PRs #41675 and #41646.

Note: PR #41717 (Speech Recognition Optimization) has been successfully merged! 🎉

@faizan842
Copy link
Contributor Author

Closing this PR as it has a persistent test failure that appears to be environmental or related to test infrastructure. The changes are minimal type hint updates that can be revisited in a future PR if needed.

Note: The main achievement was PR #41717 (Speech Recognition Optimization) which has been successfully merged! 🎉

@faizan842 faizan842 closed this Oct 20, 2025
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.

1 participant