Skip to content

Commit ae065f8

Browse files
bpo-45616: Let py.exe distinguish between v3.1 and v3.10 (GH-29731)
(cherry picked from commit f9de97a) Co-authored-by: Zachary Ware <zach@python.org>
1 parent 327c764 commit ae065f8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix Python Launcher's ability to distinguish between versions 3.1 and 3.10
2+
when either one is explicitly requested. Previously, 3.1 would be used if
3+
3.10 was requested but not installed, and 3.10 would be used if 3.1 was
4+
requested but 3.10 was installed.

PC/launcher.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,17 @@ find_python_by_version(wchar_t const * wanted_ver)
542542
}
543543
for (i = 0; i < num_installed_pythons; i++, ip++) {
544544
n = wcslen(ip->version);
545-
if (n > wlen)
545+
/*
546+
* If wlen is greater than 1, we're probably trying to find a specific
547+
* version and thus want an exact match: 3.1 != 3.10. Otherwise, we
548+
* just want a prefix match.
549+
*/
550+
if ((wlen > 1) && (n != wlen)) {
551+
continue;
552+
}
553+
if (n > wlen) {
546554
n = wlen;
555+
}
547556
if ((wcsncmp(ip->version, wanted_ver, n) == 0) &&
548557
/* bits == 0 => don't care */
549558
((bits == 0) || (ip->bits == bits))) {

0 commit comments

Comments
 (0)