Skip to content

ty: un-ignore invalid-type-form - #15387

Merged
cclauss merged 6 commits into
TheAlgorithms:masterfrom
Khushi-Tyagi9:ty-invalid-type-form
Sep 21, 2026
Merged

cclauss merged 6 commits into
TheAlgorithms:masterfrom
Khushi-Tyagi9:ty-invalid-type-form

Conversation

@Khushi-Tyagi9

@Khushi-Tyagi9 Khushi-Tyagi9 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Part of #15187.

Image here is the PIL.Image module, not the class, so ty flagged it under
invalid-type-form. Changed the annotations to Image.Image in
mean_threshold, otsu_threshold, change_brightness and change_contrast, and
removed the rule from the ignore list in pyproject.toml.

Ran ty with the rule enabled and it's clean now. Only annotations changed,
nothing at runtime.

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Sep 21, 2026
@TheAlgorithms TheAlgorithms deleted a comment from oga35767-eng Sep 21, 2026
@TheAlgorithms TheAlgorithms deleted a comment from oga35767-eng Sep 21, 2026
@cclauss

cclauss commented Sep 21, 2026

Copy link
Copy Markdown
Member

@priya-sundaram-dev, please review.

@priya-sundaram-dev priya-sundaram-dev left a comment

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.

LGTM — the four annotations that changed are genuinely the correct fix: Image is the module (from PIL import Image), and the actual image type is the Image.Image class, so -> Image.Image is right and -> Image was the invalid-type-form. With those fixed, dropping rules.invalid-type-form = "ignore" is safe and the ty CI check is green on this head, so the rule is now genuinely enforced rather than suppressed.

One small consistency note (non-blocking, fine as a follow-up): the parameter annotations still read image: Image / img: Image, i.e. the same module-vs-class distinction on the input side. ty isn't flagging them today so CI stays green, but tightening those to Image.Image too would make each signature read consistently. Happy either way — the PR as-is achieves its stated goal of un-ignoring the rule with green CI.

Comment thread computer_vision/mean_threshold.py Outdated
Comment thread computer_vision/otsu_threshold.py Outdated
@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 21, 2026
Comment thread digital_image_processing/change_brightness.py Outdated
Comment thread digital_image_processing/change_contrast.py Outdated
Co-authored-by: Christian Clauss <cclauss@me.com>
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Sep 21, 2026
@cclauss
cclauss merged commit a10a1ce into TheAlgorithms:master Sep 21, 2026
6 checks passed
@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 21, 2026
@priya-sundaram-dev

Copy link
Copy Markdown
Contributor

Came to this just after the merge — for the record it looks right to me. Since these files do from PIL import Image, the bare Image annotation was actually the module, so ty was correct to flag invalid-type-form; Image.Image is the intended PIL.Image.Image class. Pure annotation change, no runtime effect, and dropping the rule from the ignore list is the right cleanup. Nice one, @Khushi-Tyagi9. 👍

@Khushi-Tyagi9
Khushi-Tyagi9 deleted the ty-invalid-type-form branch September 21, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants