Skip to content

Commit

Permalink
Avoid importing contextlib in _virtualenv (#2688)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Feb 21, 2024
1 parent c221b32 commit e72dea8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2688.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid importing :mod:`contextlib` in ``_virtualenv.py``
5 changes: 3 additions & 2 deletions src/virtualenv/create/via_global_ref/_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 e72dea8

Please sign in to comment.