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
Complete type annotations in pip/_internal/commands
#10182
Conversation
@@ -18,7 +18,7 @@ | |||
# in a test-related module). | |||
# Finally, we need to pass an iterable of pairs here rather than a dict | |||
# so that the ordering won't be lost when using Python 2.7. | |||
commands_dict = OrderedDict([ | |||
commands_dict: "OrderedDict[str, CommandInfo]" = OrderedDict([ |
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.
You need to jump through some hoops for this to work on 3.6.
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import OrderedDict
else:
from collections import OrderedDict
commands_dict: "OrderedDict[str, CommandInfo]" = OrderedDict(...)
But does this have to be an ordered dict? Usually it's good enough to just annotate this as dict.
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.
But does this have to be an ordered dict? Usually it's good enough to just annotate this as dict.
Agree, I'll change OrderedDict
to Dict
.
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.
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.
Yup 👍
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.
FWIW, given that we're Python 3.6+, we can also just change this into a dictionary; since those are ordered starting Python 3.6.
But that can be done separately.
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.
Sounds good, thanks for the suggestion!
Complete type annotations in
pip/_internal/commands
.