Skip to content

Commit d0139e9

Browse files
committed
Merge branch 'main' into pep-669
2 parents 662c16c + fda95aa commit d0139e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1583
-1240
lines changed

.devcontainer/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM docker.io/library/fedora:37
2+
3+
ENV CC=clang
4+
5+
ENV WASI_SDK_VERSION=19
6+
ENV WASI_SDK_PATH=/opt/wasi-sdk
7+
8+
ENV WASMTIME_HOME=/opt/wasmtime
9+
ENV WASMTIME_VERSION=7.0.0
10+
ENV WASMTIME_CPU_ARCH=x86_64
11+
12+
RUN dnf -y --nodocs install git clang xz python3-blurb dnf-plugins-core && \
13+
dnf -y --nodocs builddep python3 && \
14+
dnf -y clean all
15+
16+
RUN mkdir ${WASI_SDK_PATH} && \
17+
curl --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-linux.tar.gz | \
18+
tar --strip-components 1 --directory ${WASI_SDK_PATH} --extract --gunzip
19+
20+
RUN mkdir --parents ${WASMTIME_HOME} && \
21+
curl --location "https://github.com/bytecodealliance/wasmtime/releases/download/v${WASMTIME_VERSION}/wasmtime-v${WASMTIME_VERSION}-${WASMTIME_CPU_ARCH}-linux.tar.xz" | \
22+
xz --decompress | \
23+
tar --strip-components 1 --directory ${WASMTIME_HOME} -x && \
24+
ln -s ${WASMTIME_HOME}/wasmtime /usr/local/bin

.devcontainer/devcontainer.json

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile"
4+
},
5+
"onCreateCommand": [
6+
// Install common tooling.
7+
"dnf",
8+
"install",
9+
"-y",
10+
"which",
11+
"zsh",
12+
"fish"
13+
],
14+
"updateContentCommand": {
15+
// Using the shell for `nproc` usage.
16+
"python": "./configure --config-cache --with-pydebug && make -s -j `nproc`",
17+
"docs": [
18+
"make",
19+
"--directory",
20+
"Doc",
21+
"venv",
22+
"html"
23+
]
24+
},
25+
"customizations": {
26+
"vscode": {
27+
"extensions": [
28+
// Highlighting for Parser/Python.asdl.
29+
"brettcannon.zephyr-asdl",
30+
// Highlighting for configure.ac.
31+
"maelvalais.autoconf",
32+
// C auto-complete.
33+
"ms-vscode.cpptools",
34+
// To view built docs.
35+
"ms-vscode.live-server"
36+
// https://github.com/microsoft/vscode-python/issues/18073
37+
// "ms-python.python"
38+
],
39+
"settings": {
40+
"C_Cpp.default.cStandard": "c11",
41+
"C_Cpp.default.defines": [
42+
"Py_BUILD_CORE"
43+
],
44+
// https://github.com/microsoft/vscode-cpptools/issues/10732
45+
"C_Cpp.errorSquiggles": "disabled",
46+
"editor.insertSpaces": true,
47+
"editor.rulers": [
48+
80
49+
],
50+
"editor.tabSize": 4,
51+
"editor.trimAutoWhitespace": true,
52+
"files.associations": {
53+
"*.h": "c"
54+
},
55+
"files.encoding": "utf8",
56+
"files.eol": "\n",
57+
"files.insertFinalNewline": true,
58+
"files.trimTrailingWhitespace": true,
59+
"python.analysis.diagnosticSeverityOverrides": {
60+
// Complains about shadowing the stdlib w/ the stdlib.
61+
"reportShadowedImports": "none",
62+
// Doesn't like _frozen_importlib.
63+
"reportMissingImports": "none"
64+
},
65+
"python.analysis.extraPaths": [
66+
"Lib"
67+
],
68+
"python.defaultInterpreterPath": "./python",
69+
"[restructuredtext]": {
70+
"editor.tabSize": 3
71+
}
72+
}
73+
}
74+
}
75+
}

Doc/howto/logging-cookbook.rst

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,23 +340,27 @@ adding a ``filters`` section parallel to ``formatters`` and ``handlers``:
340340

341341
.. code-block:: json
342342
343-
"filters": {
344-
"warnings_and_below": {
345-
"()" : "__main__.filter_maker",
346-
"level": "WARNING"
343+
{
344+
"filters": {
345+
"warnings_and_below": {
346+
"()" : "__main__.filter_maker",
347+
"level": "WARNING"
348+
}
347349
}
348350
}
349351
350352
and changing the section on the ``stdout`` handler to add it:
351353

352354
.. code-block:: json
353355
354-
"stdout": {
355-
"class": "logging.StreamHandler",
356-
"level": "INFO",
357-
"formatter": "simple",
358-
"stream": "ext://sys.stdout",
359-
"filters": ["warnings_and_below"]
356+
{
357+
"stdout": {
358+
"class": "logging.StreamHandler",
359+
"level": "INFO",
360+
"formatter": "simple",
361+
"stream": "ext://sys.stdout",
362+
"filters": ["warnings_and_below"]
363+
}
360364
}
361365
362366
A filter is just a function, so we can define the ``filter_maker`` (a factory

Doc/library/typing.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ For a summary of deprecated features and a deprecation timeline, please see
4141

4242
.. seealso::
4343

44+
For a quick overview of type hints, refer to
45+
`this cheat sheet <https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html>`_.
46+
47+
The "Type System Reference" section of https://mypy.readthedocs.io/ -- since
48+
the Python typing system is standardised via PEPs, this reference should
49+
broadly apply to most Python type checkers, although some parts may still be
50+
specific to mypy.
51+
4452
The documentation at https://typing.readthedocs.io/ serves as useful reference
4553
for type system features, useful typing related tools and typing best practices.
4654

47-
4855
.. _relevant-peps:
4956

5057
Relevant PEPs

Include/cpython/object.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,18 @@ struct _typeobject {
234234
* It should should be treated as an opaque blob
235235
* by code other than the specializer and interpreter. */
236236
struct _specialization_cache {
237+
// In order to avoid bloating the bytecode with lots of inline caches, the
238+
// members of this structure have a somewhat unique contract. They are set
239+
// by the specialization machinery, and are invalidated by PyType_Modified.
240+
// The rules for using them are as follows:
241+
// - If getitem is non-NULL, then it is the same Python function that
242+
// PyType_Lookup(cls, "__getitem__") would return.
243+
// - If getitem is NULL, then getitem_version is meaningless.
244+
// - If getitem->func_version == getitem_version, then getitem can be called
245+
// with two positional arguments and no keyword arguments, and has neither
246+
// *args nor **kwargs (as required by BINARY_SUBSCR_GETITEM):
237247
PyObject *getitem;
248+
uint32_t getitem_version;
238249
};
239250

240251
/* The *real* layout of a type object when allocated on the heap */

Include/internal/pycore_code.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ typedef struct {
4747

4848
typedef struct {
4949
uint16_t counter;
50-
uint16_t type_version[2];
51-
uint16_t func_version;
5250
} _PyBinarySubscrCache;
5351

5452
#define INLINE_CACHE_ENTRIES_BINARY_SUBSCR CACHE_ENTRIES(_PyBinarySubscrCache)

Include/internal/pycore_global_objects.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@ extern "C" {
2323
// Only immutable objects should be considered runtime-global.
2424
// All others must be per-interpreter.
2525

26-
#define _Py_CACHED_OBJECT(NAME) \
27-
_PyRuntime.cached_objects.NAME
28-
29-
struct _Py_cached_objects {
30-
PyObject *interned_strings;
31-
/* A thread state tied to the main interpreter,
32-
used exclusively for when a global object (e.g. interned strings)
33-
is resized (i.e. deallocated + allocated) from an arbitrary thread. */
34-
PyThreadState main_tstate;
35-
};
36-
3726
#define _Py_GLOBAL_OBJECT(NAME) \
3827
_PyRuntime.static_objects.NAME
3928
#define _Py_SINGLETON(NAME) \
@@ -69,6 +58,8 @@ struct _Py_static_objects {
6958
(interp)->cached_objects.NAME
7059

7160
struct _Py_interp_cached_objects {
61+
PyObject *interned_strings;
62+
7263
/* AST */
7364
PyObject *str_replace_inf;
7465

Include/internal/pycore_import.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ struct _import_runtime_state {
1414
which is just about every time an extension module is imported.
1515
See PyInterpreterState.modules_by_index for more info. */
1616
Py_ssize_t last_module_index;
17-
/* A dict mapping (filename, name) to PyModuleDef for modules.
18-
Only legacy (single-phase init) extension modules are added
19-
and only if they support multiple initialization (m_size >- 0)
20-
or are imported in the main interpreter.
21-
This is initialized lazily in _PyImport_FixupExtensionObject().
22-
Modules are added there and looked up in _imp.find_extension(). */
23-
PyObject *extensions;
17+
struct {
18+
/* A thread state tied to the main interpreter,
19+
used exclusively for when the extensions dict is access/modified
20+
from an arbitrary thread. */
21+
PyThreadState main_tstate;
22+
/* A dict mapping (filename, name) to PyModuleDef for modules.
23+
Only legacy (single-phase init) extension modules are added
24+
and only if they support multiple initialization (m_size >- 0)
25+
or are imported in the main interpreter.
26+
This is initialized lazily in _PyImport_FixupExtensionObject().
27+
Modules are added there and looked up in _imp.find_extension(). */
28+
PyObject *dict;
29+
} extensions;
2430
/* Package context -- the full module name for package imports */
2531
const char * pkgcontext;
2632
};

Include/internal/pycore_opcode.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_pystate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate);
129129

130130
extern void _PyThreadState_InitDetached(PyThreadState *, PyInterpreterState *);
131131
extern void _PyThreadState_ClearDetached(PyThreadState *);
132-
133-
extern PyObject * _Py_AddToGlobalDict(PyObject *, PyObject *, PyObject *);
132+
extern void _PyThreadState_BindDetached(PyThreadState *);
133+
extern void _PyThreadState_UnbindDetached(PyThreadState *);
134134

135135

136136
static inline void

Include/internal/pycore_runtime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ typedef struct pyruntimestate {
163163
} types;
164164

165165
/* All the objects that are shared by the runtime's interpreters. */
166-
struct _Py_cached_objects cached_objects;
167166
struct _Py_static_objects static_objects;
168167

169168
/* The following fields are here to avoid allocation during init.

Include/internal/pycore_runtime_init.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ extern PyTypeObject _PyExc_MemoryError;
4141
in accordance with the specification. */ \
4242
.autoTSSkey = Py_tss_NEEDS_INIT, \
4343
.parser = _parser_runtime_state_INIT, \
44+
.imports = { \
45+
.extensions = { \
46+
.main_tstate = _PyThreadState_INIT, \
47+
}, \
48+
}, \
4449
.ceval = { \
4550
.perf = _PyEval_RUNTIME_PERF_INIT, \
4651
}, \
@@ -59,9 +64,6 @@ extern PyTypeObject _PyExc_MemoryError;
5964
.types = { \
6065
.next_version_tag = 1, \
6166
}, \
62-
.cached_objects = { \
63-
.main_tstate = _PyThreadState_INIT, \
64-
}, \
6567
.static_objects = { \
6668
.singletons = { \
6769
.small_ints = _Py_small_ints_INIT, \

Include/internal/pycore_unicodeobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ struct _Py_unicode_runtime_ids {
3434

3535
struct _Py_unicode_runtime_state {
3636
struct _Py_unicode_runtime_ids ids;
37-
/* The interned dict is at _PyRuntime.cached_objects.interned_strings. */
3837
};
3938

4039
/* fs_codec.encoding is initialized to NULL.
@@ -60,6 +59,7 @@ struct _Py_unicode_state {
6059
struct _Py_unicode_ids ids;
6160
};
6261

62+
extern void _PyUnicode_InternInPlace(PyInterpreterState *interp, PyObject **p);
6363
extern void _PyUnicode_ClearInterned(PyInterpreterState *interp);
6464

6565

0 commit comments

Comments
 (0)