-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add urllib3.contrib.socks
; improve urllib3.connectionpool
#8457
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
As well as @srittau's points, note that this module only imports successfully if the optional dependency |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
def __exit__(self, exc_type, exc_val, exc_tb): ... | ||
def close(self): ... | ||
scheme: ClassVar[str | None] | ||
QueueCls: ClassVar[type[LifoQueue]] |
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.
I still think this would be better as the stdlib Queue[Any]
. It's true that at runtime, ConnectionPool.QueueCls
is urllib3.util.queue.LifoQueue
. But ConnectionPool
is a base class for other ConnectionPool
classes, and I don't think (from my impression, from reading the code) that it's mandatory for all subclasses to have their QueueCls
attribute be a subclass of urllib3.util.queue.LifoQueue
. It seems to me that anything with an interface similar to the stdlib queue.Queue
class will do. There's evidence for this in the fact that they scrapped the urllib3.util.queue
submodule in the main
branch and switched to using the stdlib queue
module.
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.
Anyway, this is minor, other than this it looks good to me now :)
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.
👍 I think I got mixed up between the type[_QueueT]
change and the Queue[Any]
change. I agree with you on that.
If you are comfortable with it, I will update this to: ClassVar[type[Queue[Any]]]
and change the imports to be fully qualified to differentiate between the two different queues.
Sound good?
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.
That sounds good to me! 👍
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.
That was changed in 3e231f4 (I expect a pre-commit will trigger). The only thing I may have missed was if there was a better way to import the LifoQueue
to avoid the overlapping module names. As it stands, I've updated it to import queue
for the standard library instance and usage as queue.Queue[Any]
and have left the urllib3 LifoQueue
as from .util.queue import LifoQueue
.
My concern was that from .util import queue as _queue
would be even more confusing with both queue.Queue
and _queue.LifoQueue
given that both have a LifoQueue
Hopefully thats correct
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.
How about from .util import queue as urllib3queue
? And then refer to it as urllib3queue.LifoQueue
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.
I had thought that was going to trigger a stubtest warning about it not existing at runtime, but I could just be getting confused about what is checked and what isn't.
That's a good approach, thank you for the suggestion, worst case we can do it as from .util import queue as _urllib3queue
to avoid the check
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.
All imports in stub files are considered "private to the stub" (not re-exported), unless they fall into one of the two categories:
import foo as foo
-- theas
has to be truly redundant; if you doimport foo as bar
, it's still considered private, butimport foo as foo
is considered a public re-export.from foo import *
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.
-- A third exception is if a name is included in __all__
, it's always considered re-exported, even if it's imported via a means that would usually make it a "private" import.
This comment has been minimized.
This comment has been minimized.
urllib3.contrib.socks
; improve urllib3.connectionpool
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.
Not an in-depth review, but everything looked fine at first glance. I'll defer to @AlexWaygood's judgement.
Let's land it. Thanks for working on this @kkirsche, this was a tricky one in lots of ways! |
My pleasure, trying to work towards larger and loftier goals, so hopefully experiences like this will help |
This is required to address some re-exports in #8439
The source code is available here:
https://github.com/urllib3/urllib3/blob/main/src/urllib3/contrib/socks.py