-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 type checking error #3365
mypy: fix type checking error #3365
Conversation
error: Argument 1 to "_answerCard" of "Reviewer" has incompatible type "int"; expected "Literal[1, 2, 3, 4]" [arg-type]
qt/aqt/reviewer.py
Outdated
def generate_default_answer_keys(): | ||
for ease in aqt.mw.pm.default_answer_keys: | ||
key = aqt.mw.pm.get_answer_key(ease) | ||
if key: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Walrus operator would make this more concise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should key
only be not None
or does it also need to be different from the empty string?
In other words: I would like to change if key:
to if key is not None:
, provided this doesn't change its meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user can enter an empty string in the preferences, so we also need to guard against that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for fixing the code. I wasn't sure about that.
to avoid nesting.
🚀 |
To have an easier time in my other pull requests, when figuring out which type errors were introduced by me and which already existed, I'm fixing some of the type errors on the current main branch.
This pull request fixes this mypy error:
The function
_answerCard
wants only numbers 1, 2, 3 or 4 (that is, a variable of typeLiteral[1, 2, 3, 4]
. But we're passing a variable of typeint
which can hold many more numbers than these mentioned four.I'm basically just
int
toLiteral[1, 2, 3, 4]
(which by itself would already suffice)