Backport start_tls() support for Python 3.6#521
Conversation
|
Fantastic stuff! I guess this PR should also update the |
yeraydiazdiaz
left a comment
There was a problem hiding this comment.
LGTM, thanks @sethmlarson! 🌟
florimondmanca
left a comment
There was a problem hiding this comment.
Awesome! Approving in advance provided we update the test mentioned by Tom. :) Thanks!
|
At a later date I may look at moving this out to a coverage-excluded |
| if hasattr(loop, "start_tls"): | ||
| loop_start_tls = loop.start_tls # type: ignore |
There was a problem hiding this comment.
Removing the type: ignore after changing the if statement to be if sys.version_info >= (3, 7) should pass CI with mypy>=0.730.
There was a problem hiding this comment.
Unfortunately we can't assume that loops on Python 3.6 don't have start_tls(). Uvloop supports 3.6 and supports start_tls(). That's interesting that mypy knows about features though! Would an assert work here?
There was a problem hiding this comment.
getattr would work around any typing issues too.
There was a problem hiding this comment.
Ah I didn't know about uvloop 😞
That's interesting that mypy knows about features though!
It knows about if/else with sys.version_info comparisons but that's all. It's very limited.
Would an assert work here?
I don't think we can assert much about the function at runtime, unfortunately. Could maybe do something with typing.cast but probably not worth the effort.
florimondmanca
left a comment
There was a problem hiding this comment.
I removed the version check for 3.6 on the start_tls test, all tests passing!
Mental note that we should refactor sometime in the future to have a compat.py file with this kind of version-specific patching.
Anyway, merging now, thanks @sethmlarson!
This adds support for proxy tunnels for Python 3.6 + asyncio.
Based almost entirely on this comment: urllib3/urllib3#1323 (comment) Massive thanks to @florimondmanca for finding this!
Closes #515.