From 4dfb894001360e0972fb9970ed5ad6bbbd17250a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Randy=20D=C3=B6ring?=
 <30527984+radoering@users.noreply.github.com>
Date: Sat, 18 Mar 2023 20:57:37 +0100
Subject: [PATCH] installer: fix optimization level (#7666)

---
 src/poetry/installation/wheel_installer.py | 2 +-
 tests/installation/test_wheel_installer.py | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/poetry/installation/wheel_installer.py b/src/poetry/installation/wheel_installer.py
index 16de86e3022..ab2e0a82f3e 100644
--- a/src/poetry/installation/wheel_installer.py
+++ b/src/poetry/installation/wheel_installer.py
@@ -94,7 +94,7 @@ def __init__(self, env: Env) -> None:
         )
 
     def enable_bytecode_compilation(self, enable: bool = True) -> None:
-        self._destination.bytecode_optimization_levels = (1,) if enable else ()
+        self._destination.bytecode_optimization_levels = (-1,) if enable else ()
 
     def install(self, wheel: Path) -> None:
         with WheelFile.open(wheel) as source:
diff --git a/tests/installation/test_wheel_installer.py b/tests/installation/test_wheel_installer.py
index 7fc4826f940..b7b3d7c7c93 100644
--- a/tests/installation/test_wheel_installer.py
+++ b/tests/installation/test_wheel_installer.py
@@ -77,5 +77,7 @@ def test_enable_bytecode_compilation(
     if compile:
         assert cache_dir.exists()
         assert list(cache_dir.glob("*.pyc"))
+        assert not list(cache_dir.glob("*.opt-1.pyc"))
+        assert not list(cache_dir.glob("*.opt-2.pyc"))
     else:
         assert not cache_dir.exists()