Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30758ba

Browse files
committed
Merge branch 'main' into copy-replace-structseq
2 parents 38f331b + 1001233 commit 30758ba

27 files changed

+742
-138
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.0.288
3+
rev: v0.0.292
44
hooks:
55
- id: ruff
66
name: Run Ruff on Lib/test/

Include/cpython/initconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ typedef struct PyConfig {
204204
wchar_t *run_module;
205205
wchar_t *run_filename;
206206

207+
/* --- Set by Py_Main() -------------------------- */
208+
wchar_t *sys_path_0;
209+
207210
/* --- Private fields ---------------------------- */
208211

209212
// Install importlib? If equals to 0, importlib is not initialized at all.

Include/cpython/pystate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ struct _ts {
211211
* if it is NULL. */
212212
PyAPI_FUNC(PyThreadState *) _PyThreadState_UncheckedGet(void);
213213

214+
214215
// Disable tracing and profiling.
215216
PyAPI_FUNC(void) PyThreadState_EnterTracing(PyThreadState *tstate);
216217

Include/internal/pycore_interp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct _is {
7373
uint64_t next_unique_id;
7474
/* The linked list of threads, newest first. */
7575
PyThreadState *head;
76+
/* The thread currently executing in the __main__ module, if any. */
77+
PyThreadState *main;
7678
/* Used in Modules/_threadmodule.c. */
7779
long count;
7880
/* Support for runtime thread stack size tuning.

Include/internal/pycore_pystate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ _Py_IsMainInterpreterFinalizing(PyInterpreterState *interp)
4444
interp == &_PyRuntime._main_interpreter);
4545
}
4646

47+
// Export for _xxsubinterpreters module.
48+
PyAPI_FUNC(int) _PyInterpreterState_SetRunningMain(PyInterpreterState *);
49+
PyAPI_FUNC(void) _PyInterpreterState_SetNotRunningMain(PyInterpreterState *);
50+
PyAPI_FUNC(int) _PyInterpreterState_IsRunningMain(PyInterpreterState *);
51+
4752

4853
static inline const PyConfig *
4954
_Py_GetMainConfig(void)

Lib/dis.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,14 @@ def _test():
901901
import argparse
902902

903903
parser = argparse.ArgumentParser()
904+
parser.add_argument('-C', '--show-caches', action='store_true',
905+
help='show inline caches')
904906
parser.add_argument('infile', type=argparse.FileType('rb'), nargs='?', default='-')
905907
args = parser.parse_args()
906908
with args.infile as infile:
907909
source = infile.read()
908910
code = compile(source, args.infile.name, "exec")
909-
dis(code)
911+
dis(code, show_caches=args.show_caches)
910912

911913
if __name__ == "__main__":
912914
_test()

Lib/random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
try:
6767
# hashlib is pretty heavy to load, try lean internal module first
68-
from _sha512 import sha512 as _sha512
68+
from _sha2 import sha512 as _sha512
6969
except ImportError:
7070
# fallback to official implementation
7171
from hashlib import sha512 as _sha512

Lib/test/.ruff.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ extend-exclude = [
2626
"test_keywordonlyarg.py",
2727
"test_pkg.py",
2828
"test_subclassinit.py",
29-
"test_typing.py",
3029
"test_unittest/testmock/testpatch.py",
3130
"test_yield_from.py",
3231
"time_hashlib.py",

Lib/test/support/interpreters.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
# aliases:
88
from _xxsubinterpreters import is_shareable
99
from _xxinterpchannels import (
10-
ChannelError, ChannelNotFoundError, ChannelEmptyError,
10+
ChannelError, ChannelNotFoundError, ChannelClosedError,
11+
ChannelEmptyError, ChannelNotEmptyError,
1112
)
1213

1314

@@ -117,10 +118,16 @@ def list_all_channels():
117118
class _ChannelEnd:
118119
"""The base class for RecvChannel and SendChannel."""
119120

120-
def __init__(self, id):
121-
if not isinstance(id, (int, _channels.ChannelID)):
122-
raise TypeError(f'id must be an int, got {id!r}')
123-
self._id = id
121+
_end = None
122+
123+
def __init__(self, cid):
124+
if self._end == 'send':
125+
cid = _channels._channel_id(cid, send=True, force=True)
126+
elif self._end == 'recv':
127+
cid = _channels._channel_id(cid, recv=True, force=True)
128+
else:
129+
raise NotImplementedError(self._end)
130+
self._id = cid
124131

125132
def __repr__(self):
126133
return f'{type(self).__name__}(id={int(self._id)})'
@@ -147,6 +154,8 @@ def id(self):
147154
class RecvChannel(_ChannelEnd):
148155
"""The receiving end of a cross-interpreter channel."""
149156

157+
_end = 'recv'
158+
150159
def recv(self, *, _sentinel=object(), _delay=10 / 1000): # 10 milliseconds
151160
"""Return the next object from the channel.
152161
@@ -171,10 +180,15 @@ def recv_nowait(self, default=_NOT_SET):
171180
else:
172181
return _channels.recv(self._id, default)
173182

183+
def close(self):
184+
_channels.close(self._id, recv=True)
185+
174186

175187
class SendChannel(_ChannelEnd):
176188
"""The sending end of a cross-interpreter channel."""
177189

190+
_end = 'send'
191+
178192
def send(self, obj):
179193
"""Send the object (i.e. its data) to the channel's receiving end.
180194
@@ -196,3 +210,9 @@ def send_nowait(self, obj):
196210
# None. This should be fixed when channel_send_wait() is added.
197211
# See bpo-32604 and gh-19829.
198212
return _channels.send(self._id, obj)
213+
214+
def close(self):
215+
_channels.close(self._id, send=True)
216+
217+
218+
_channels._register_end_types(SendChannel, RecvChannel)

Lib/test/test_embed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
505505
'run_command': None,
506506
'run_module': None,
507507
'run_filename': None,
508+
'sys_path_0': None,
508509

509510
'_install_importlib': 1,
510511
'check_hash_pycs_mode': 'default',
@@ -1132,6 +1133,7 @@ def test_init_run_main(self):
11321133
'program_name': './python3',
11331134
'run_command': code + '\n',
11341135
'parse_argv': 2,
1136+
'sys_path_0': '',
11351137
}
11361138
self.check_all_configs("test_init_run_main", config, api=API_PYTHON)
11371139

@@ -1147,6 +1149,7 @@ def test_init_main(self):
11471149
'run_command': code + '\n',
11481150
'parse_argv': 2,
11491151
'_init_main': 0,
1152+
'sys_path_0': '',
11501153
}
11511154
self.check_all_configs("test_init_main", config,
11521155
api=API_PYTHON,

0 commit comments

Comments
 (0)