Skip to content

made dependencies on certifi and httpcore only load when required - #3377

Merged
lovelydinosaur merged 4 commits into
encode:masterfrom
joemarshall:lazy_load_httpcore
Oct 29, 2024
Merged

made dependencies on certifi and httpcore only load when required#3377
lovelydinosaur merged 4 commits into
encode:masterfrom
joemarshall:lazy_load_httpcore

Conversation

@joemarshall

Copy link
Copy Markdown
Contributor

As per #3330 this makes certifi and httpcore only load when required.

For now I haven't done the same with ssl, because SSLContext derives from ssl, which makes it a pain to load on demand. I can make that behind an ImportError guard, with a dummy SSLContext class, but it is a bit hacky. This is what asyncio does. The alterative is dynamically reloading the class and importing ssl on first instantiation (or overriding __new__ maybe), but again, it is a bit of a hack.

Personally I think there isn't a massive overhead to just making ssl a dependency even on platforms where it isn't being used, but I'm easy to go with the dummy class or something if you don't want that; I just worry that code may assume that the dummy SSLContext is a class derived from ssl.SSLContext and bad things will occur.

@joemarshall

Copy link
Copy Markdown
Contributor Author

@tomchristie here's the change to lazy load httpcore and certifi

@lovelydinosaur

Copy link
Copy Markdown
Member

Nice work @joemarshall, thanks!

For the ssl case, this is probably okay for the implementation...

if ssl is None:
    class SSLContext:
        def __init__(self, ...):
            raise RuntimeError('...')
else:
    ...

With typechecking gates around the other cases.

Maintain existing version until we make a release PR.

@lovelydinosaur lovelydinosaur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

@lovelydinosaur
lovelydinosaur merged commit e9cabc8 into encode:master Oct 29, 2024
@lovelydinosaur lovelydinosaur mentioned this pull request Nov 15, 2024
@lovelydinosaur lovelydinosaur mentioned this pull request Nov 28, 2024
samclearman pushed a commit to titanmsp/httpx that referenced this pull request Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants