Skip to content

ty: un-ignore invalid-return-type rule - #15600

Closed
SirHumza wants to merge 1 commit into
TheAlgorithms:masterfrom
SirHumza:ty/un-ignore-invalid-return-type
Closed

SirHumza wants to merge 1 commit into
TheAlgorithms:masterfrom
SirHumza:ty/un-ignore-invalid-return-type

Conversation

@SirHumza

Copy link
Copy Markdown

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?

Contributes to #15187.

Removes rules.invalid-return-type = "ignore" from [tool.ty]. On a synced Python 3.15 (regular GIL) environment the rule now reports zero diagnostics.

Files fixed:

  • data_structures/arrays/dynamic_array.py -- annotated self.array as list[int | None] and narrowed the value in get (the bounds check already guarantees a filled slot).
  • graphs/bi_directional_dijkstra.py -- bidirectional_dij can return the np.inf sentinel / fractional path cost, so the return annotation is float, not int.
  • graphs/hopcroft_karp.py -- pair_left stores T | object (the _NIL sentinel); the comprehension filters _NIL out, so the result is cast to dict[T, T].
  • computer_vision/mosaic_augmentation.py -- the returned image is an np.ndarray, not a list; annotated the return as tuple[np.ndarray, list, str] and typed path_list as list[str].
  • machine_learning/mfcc.py -- mel_to_freq is called with both a scalar and an array; added overloads so the array call returns an np.ndarray (matching its tuple[np.ndarray, np.ndarray] return annotation).
  • networking_flow/ford_fulkerson.py -- the graph is untyped (list), so the accumulator can be int | float; widened the return annotation accordingly.
  • other/dancing_links.py -- _choose_column can return None when no columns remain (already handled by the caller); annotated ColumnNode | None.
  • web_programming/random_anime_character.py -- narrowed the parsed <meta> content to str before returning the tuple[str, str, str].

Verification (uv sync --python 3.15, then uv run --python 3.15 --with ty ty check):

  • No invalid-return-type diagnostics remain and the total diagnostic count does not increase.
  • doctests pass for the touched modules (dynamic_array.py, bi_directional_dijkstra.py, dancing_links.py, mfcc.py, hopcroft_karp.py, ford_fulkerson.py).
  • ruff check and ruff format --check clean on the touched files.

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".

@SirHumza
SirHumza requested a review from cclauss as a code owner October 18, 2026 13:38
@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Oct 18, 2026
@SirHumza SirHumza closed this by deleting the head repository Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant