The Wayback Machine - https://web.archive.org/web/20220111020354/https://github.com/TheAlgorithms/Python/pull/5814
Skip to content
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

[Mypy] fix other/least_recently_used #5814

Merged
merged 18 commits into from Nov 16, 2021

Conversation

@spazm
Copy link
Contributor

@spazm spazm commented Nov 11, 2021

Describe your change:

  • fix bug in dq_removal code. Needed to pass key to .remove() rather than index.
  • remove incorrect annotation to make the __init__ an abstract function.
  • Annotate all functions and class Generic[T]
  • Expand example to show creating a LRUCache over concrete and mixed types.
  • Adds doctest to LRUCache class
  • Adds assert test in main.

Previously opened as #5656

Closes: #4052

Before

% git checkout master
Your branch is up to date with 'origin/master'.

% mypy --ignore-missing-imports --install-types least_recently_used.py
least_recently_used.py:57: error: Cannot instantiate abstract class "LRUCache" with abstract attribute "__init__"
Found 1 error in 1 file (checked 1 source file)
% mypy --strict least_recently_used.py
least_recently_used.py:27: error: Function is missing a type annotation
least_recently_used.py:33: error: Unsupported right operand type for in ("object")
least_recently_used.py:34: error: Argument 1 to "len" has incompatible type "object"; expected "Sized"
least_recently_used.py:35: error: "object" has no attribute "pop"
least_recently_used.py:36: error: "object" has no attribute "remove"
least_recently_used.py:39: error: Need type annotation for "key"
least_recently_used.py:39: error: Argument 1 to "enumerate" has incompatible type "object"; expected "Iterable[<nothing>]"
least_recently_used.py:43: error: "object" has no attribute "remove"
least_recently_used.py:45: error: "object" has no attribute "appendleft"
least_recently_used.py:46: error: "object" has no attribute "add"
least_recently_used.py:48: error: Function is missing a return type annotation
least_recently_used.py:48: note: Use "-> None" if function does not return a value
least_recently_used.py:52: error: "object" has no attribute "__iter__"; maybe "__str__" or "__dir__"? (not iterable)
least_recently_used.py:57: error: Cannot instantiate abstract class "LRUCache" with abstract attribute "__init__"
least_recently_used.py:58: error: Call to untyped function "refer" in typed context
least_recently_used.py:59: error: Call to untyped function "refer" in typed context
least_recently_used.py:60: error: Call to untyped function "refer" in typed context
least_recently_used.py:61: error: Call to untyped function "refer" in typed context
least_recently_used.py:62: error: Call to untyped function "refer" in typed context
least_recently_used.py:63: error: Call to untyped function "refer" in typed context
least_recently_used.py:64: error: Call to untyped function "display" in typed context
Found 20 errors in 1 file (checked 1 source file)

After

% git checkout mypy-fix-other-least_recently_used
Switched to branch 'mypy-fix-other-least_recently_used'
Your branch is up to date with 'origin/mypy-fix-other-least_recently_used'.

% mypy --strict least_recently_used.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}.
@spazm spazm force-pushed the mypy-fix-other-least_recently_used branch from 045f54b to ec878d9 Nov 11, 2021
@spazm spazm marked this pull request as ready for review Nov 11, 2021
@spazm spazm changed the title Mypy fix other least recently used [Mypy] fix other/least_recently_used Nov 11, 2021
Copy link
Member

@cclauss cclauss left a comment

LGTM. Thanks for doing this and thanks for making us mypy compliant.

@cclauss cclauss merged commit 551c657 into TheAlgorithms:master Nov 16, 2021
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants