-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Adjust urllib3.util.url #8460
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
Adjust urllib3.util.url #8460
Conversation
This comment has been minimized.
This comment has been minimized.
stubs/urllib3/urllib3/util/url.pyi
Outdated
class Url: | ||
slots: Any | ||
auth: str | None | ||
fragment: str | None | ||
host: str | None | ||
path: str | None | ||
port: str | None | ||
query: str | None | ||
scheme: str | None |
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.
At runtime, Url
is a class that inherits from a NamedTuple
that is also called Url
. We can't mimic that in the stub exactly, but we can come pretty close by doing something like this:
class _UrlBase(NamedTuple):
auth: str | None
fragment: str | None
host: str | None
path: str | None
port: str | None
query: str | None
scheme: str | None
class Url(_UrlBase):
# rest of the class definition as it is in the stub already
(GitHub won't let me use the "suggested changes" feature here because this line range includes some deleted lines.)
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.
very interesting, thanks for the suggestion 👍
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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.
Thanks!
@AlexWaygood just out of curiosity, when do you decide to create and publish a new version of third party stubs? |
The magic typeshed bots automatically create and publish the stubs packages. I think the workflow runs once every few hours, but I'm not sure :) |
Nice, thanks! Looking forward to see the magic 😄 |
Added the missing type hints in
urllib3.util.url
and changed the attributes ofUrl
to reflect the actual attributes, which come from the subclassednamedtuple