Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6d5c2de

Browse filesBrowse files
corona10estyxx
authored andcommitted
pythongh-119132: Update sys.version to identify free-threaded or not. (pythongh-119134)
1 parent 5299bf4 commit 6d5c2de
Copy full SHA for 6d5c2de

File tree

Expand file treeCollapse file tree

3 files changed

+24
-11
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-11
lines changed

‎Lib/platform.py

Copy file name to clipboardExpand all lines: Lib/platform.py
+15-9Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,17 +1153,16 @@ def _sys_version(sys_version=None):
11531153
if result is not None:
11541154
return result
11551155

1156-
sys_version_parser = re.compile(
1157-
r'([\w.+]+)\s*' # "version<space>"
1158-
r'\(#?([^,]+)' # "(#buildno"
1159-
r'(?:,\s*([\w ]*)' # ", builddate"
1160-
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
1161-
r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"
1162-
11631156
if sys.platform.startswith('java'):
11641157
# Jython
1158+
jython_sys_version_parser = re.compile(
1159+
r'([\w.+]+)\s*' # "version<space>"
1160+
r'\(#?([^,]+)' # "(#buildno"
1161+
r'(?:,\s*([\w ]*)' # ", builddate"
1162+
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
1163+
r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"
11651164
name = 'Jython'
1166-
match = sys_version_parser.match(sys_version)
1165+
match = jython_sys_version_parser.match(sys_version)
11671166
if match is None:
11681167
raise ValueError(
11691168
'failed to parse Jython sys.version: %s' %
@@ -1190,7 +1189,14 @@ def _sys_version(sys_version=None):
11901189

11911190
else:
11921191
# CPython
1193-
match = sys_version_parser.match(sys_version)
1192+
cpython_sys_version_parser = re.compile(
1193+
r'([\w.+]+)\s*' # "version<space>"
1194+
r'(?:experimental free-threading build\s+)?' # "free-threading-build<space>"
1195+
r'\(#?([^,]+)' # "(#buildno"
1196+
r'(?:,\s*([\w ]*)' # ", builddate"
1197+
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
1198+
r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"
1199+
match = cpython_sys_version_parser.match(sys_version)
11941200
if match is None:
11951201
raise ValueError(
11961202
'failed to parse CPython sys.version: %s' %
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Update :data:`sys.version` to identify whether the build is default build or
2+
free-threading build. Patch By Donghee Na.

‎Python/getversion.c

Copy file name to clipboardExpand all lines: Python/getversion.c
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
#include "patchlevel.h"
77

88
static int initialized = 0;
9-
static char version[250];
9+
static char version[300];
1010

1111
void _Py_InitVersion(void)
1212
{
1313
if (initialized) {
1414
return;
1515
}
1616
initialized = 1;
17-
PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
17+
#ifdef Py_GIL_DISABLED
18+
const char *buildinfo_format = "%.80s experimental free-threading build (%.80s) %.80s";
19+
#else
20+
const char *buildinfo_format = "%.80s (%.80s) %.80s";
21+
#endif
22+
PyOS_snprintf(version, sizeof(version), buildinfo_format,
1823
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
1924
}
2025

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.