Skip to content
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

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

Merged
merged 4 commits into from
Oct 29, 2024

Conversation

joemarshall
Copy link
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
Contributor Author

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

@tomchristie
Copy link
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.
Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

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

😎

@tomchristie tomchristie merged commit e9cabc8 into encode:master Oct 29, 2024
5 checks passed
@tomchristie tomchristie mentioned this pull request Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants