Skip to content

Commit fd185cb

Browse files
committed
gh-154377: Preserve legacy venv version warning behavior
1 parent 1b2f494 commit fd185cb

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

Lib/site.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,19 +1018,18 @@ def _venv(state):
10181018
RuntimeWarning,
10191019
)
10201020
continue
1021-
if (
1021+
if should_error:
1022+
if (major, minor) != sys.version_info[:2]:
1023+
raise RuntimeError(
1024+
f"This virtual environment was created for Python {major}.{minor}, "
1025+
f"but the current interpreter is Python "
1026+
f"{sys.version_info.major}.{sys.version_info.minor}. "
1027+
"Consider running `python -m venv --upgrade` to update the environment.",
1028+
)
1029+
elif (
10221030
major == sys.version_info.major
1023-
and minor == sys.version_info.minor
1031+
and minor != sys.version_info.minor
10241032
):
1025-
continue
1026-
if should_error:
1027-
raise RuntimeError(
1028-
f"This virtual environment was created for Python {major}.{minor}, "
1029-
f"but the current interpreter is Python "
1030-
f"{sys.version_info.major}.{sys.version_info.minor}. "
1031-
"Consider running `python -m venv --upgrade` to update the environment.",
1032-
)
1033-
else:
10341033
_warn(
10351034
f"This virtual environment was created for Python {major}.{minor}, "
10361035
f"but the current interpreter is Python "

0 commit comments

Comments
 (0)