Skip to content

[mypy] Fixes Fisher Yates shuffle and extends annotations #5653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

spazm
Copy link
Contributor

@spazm spazm commented Oct 29, 2021

Describe your change:

  1. Undo breaking change from [fixed] unused variable, standalone running, import doctest module #4673
  2. Adds TypeVar to pass strict typing

Related to: #4052

Before

% mypy --ignore-missing-imports --install-types  fischer_yates_shuffle.py
fischer_yates_shuffle.py:12: error: Argument 1 to "len" has incompatible type "Type[List[Any]]"; expected "Sized"
fischer_yates_shuffle.py:13: error: Argument 1 to "len" has incompatible type "Type[List[Any]]"; expected "Sized"
fischer_yates_shuffle.py:14: error: Argument 1 to "len" has incompatible type "Type[List[Any]]"; expected "Sized"
fischer_yates_shuffle.py:15: error: No overload variant of "__setitem__" of "list" matches argument types "int", "Type[List[Any]]"
fischer_yates_shuffle.py:15: note: Possible overload variants:
fischer_yates_shuffle.py:15: note:     def [_T] __setitem__(self, List[_T], SupportsIndex, _T) -> None
fischer_yates_shuffle.py:15: note:     def [_T] __setitem__(self, List[_T], slice, Iterable[_T]) -> None
fischer_yates_shuffle.py:15: error: Variable "a" is not valid as a type
fischer_yates_shuffle.py:15: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
fischer_yates_shuffle.py:15: error: Variable "b" is not valid as a type
fischer_yates_shuffle.py:16: error: Incompatible return value type (got "Type[List[Any]]", expected "List[Any]")
Found 7 errors in 1 file (checked 1 source file)

After fix

% mypy --ignore-missing-imports --install-types  fischer_yates_shuffle.py       
Success: no issues found in 1 source file

 % mypy --strict fischer_yates_shuffle.py
fischer_yates_shuffle.py:11: error: Missing type parameters for generic type "list"

After

% mypy --strict fischer_yates_shuffle.py
Success: no issues found in 1 source file
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • 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 have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Oct 29, 2021
@ghost
Copy link

ghost commented Oct 29, 2021

Multiple Pull Request Detected

@spazm, we are extremely excited that you want to submit multiple algorithms in this repository but we have a limit on how many pull request a user can keep open at a time. This is to make sure all maintainers and users focus on a limited number of pull requests at a time to maintain the quality of the code.

This pull request is being closed as the user already has an open pull request. Please focus on your previous pull request before opening another one. Thank you for your cooperation.

User opened pull requests (including this one): #5653, #5647, #5621, #5591

This pull request was closed.
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant