Skip to content

fixing image_utils.py todo#39941

Open
skochar1 wants to merge 5 commits into
huggingface:mainfrom
skochar1:pr_1
Open

fixing image_utils.py todo#39941
skochar1 wants to merge 5 commits into
huggingface:mainfrom
skochar1:pr_1

Conversation

@skochar1

@skochar1 skochar1 commented Aug 6, 2025

Copy link
Copy Markdown

What does this PR do?

This PR resolves a longstanding TODO in src/transformers/image_utils.py by replacing the use of logger.warning with Python’s built-in warnings.warn for notifying users of unused or invalid parameters in image processor functions. This approach makes warnings more controllable, user-friendly, and consistent with Python best practices.

Specifically, this PR:

  • Fixes a TODO comment by swapping logging for proper warning handling using warnings.warn(..., UserWarning, stacklevel=2).
  • Adds/updates docstrings and type hints for the affected functions.
  • Implements comprehensive tests in tests/utils/test_image_utils.py to cover all usage scenarios—including valid parameters, invalid parameters, and edge cases.
  • Ensures warning messages are triggered and formatted as expected.
  • Verifies correctness through syntax, imports, and end-to-end integration checks.

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?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@amyeroberts @qubvel

Failures

Failures unrelated to changes made by PR.

Comment on lines +957 to +961
warnings.warn(
f"Unused or unrecognized kwargs: {unused_key_str}. These arguments will be ignored.",
UserWarning,
stacklevel=2,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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