From e9d82cf0fa36f0f29aebf6acce6e9524b99875b1 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:23:05 -0800 Subject: [PATCH] Avoid import contextlib in `_virtualenv` (#1406) No need to pay 3ms on basically every Python invocation. I opened a PR upstream last week: https://github.com/pypa/virtualenv/pull/2688 --- crates/gourgeist/src/_virtualenv.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/gourgeist/src/_virtualenv.py b/crates/gourgeist/src/_virtualenv.py index 17f73b1d4..f5a028048 100644 --- a/crates/gourgeist/src/_virtualenv.py +++ b/crates/gourgeist/src/_virtualenv.py @@ -4,7 +4,6 @@ from __future__ import annotations import os import sys -from contextlib import suppress VIRTUALENV_PATCH_FILE = os.path.join(__file__) @@ -78,8 +77,10 @@ class _Finder: 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