Avoid building a throwaway SSL context in the HTTPS cert handler.
Review Request #15216 — Created Aug. 4, 2026 and submitted — Latest diff uploaded
On Python 3.12+,
urllib.request.HTTPSHandler.__init__builds a default
SSL context when one isn't passed in, loading the system CA store in the
process.CertificateVerificationHTTPSHandlerdidn't pass one, so every
handler we construct pays for a context thathttps_openimmediately
throws away and replaces with the managed one from the certificate
manager. Handlers are built per-request, so this isn't free.This also breaks the cert unit tests, which capture every context
created during a request and then assert against the first one. With the
extra context in the list, they inspect the throwaway instead of ours.The handler now passes a cheap placeholder context to the parent, which
https_openreplaces as before.
Ran unit tests on Python 3.10 and 3.12