Skip to content

Commit

Permalink
Avoid import contextlib in _virtualenv
Browse files Browse the repository at this point in the history
No need to pay 3ms on basically every Python invocation.
I opened a PR upstream last week: pypa/virtualenv#2688
  • Loading branch information
hauntsaninja committed Feb 16, 2024
1 parent f8fbcb2 commit 1c93a1f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/gourgeist/src/_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os
import sys
from contextlib import suppress

VIRTUALENV_PATCH_FILE = os.path.join(__file__)

Expand Down Expand Up @@ -78,8 +77,10 @@ def find_spec(self, fullname, path, target=None): # noqa: ARG002
old = getattr(spec.loader, func_name)
func = self.exec_module if is_new_api else self.load_module
if old is not func:
with suppress(AttributeError): # C-Extension loaders are r/o such as zipimporter with <3.7
try: # noqa: SIM105
setattr(spec.loader, func_name, partial(func, old))
except AttributeError:
pass # C-Extension loaders are r/o such as zipimporter with <3.7
return spec
finally:
self.fullname = None
Expand Down

0 comments on commit 1c93a1f

Please sign in to comment.