8000 Merge branch 'main' into test-lazy-import · python/cpython@efedb94 · GitHub
[go: up one dir, main page]

Skip to content

Commit efedb94

Browse files
authored
Merge branch 'main' into test-lazy-import
2 parents aa19ba5 + d270bb5 commit efedb94

39 files changed

+1336
-685
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ pdb
14661466
* Source code displayed in :mod:`pdb` will be syntax-highlighted. This feature
14671467
can be controlled using the same methods as PyREPL, in addition to the newly
14681468
added ``colorize`` argument of :class:`pdb.Pdb`.
1469-
(Contributed by Tian Gao in :gh:`133355`.)
1469+
(Contributed by Tian Gao and Łukasz Langa in :gh:`133355`.)
14701470

14711471

14721472
pickle

Include/internal/pycore_code.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,47 @@ PyAPI_FUNC(int) _PyCode_SetUnboundVarCounts(
621621
PyObject *globalsns,
622622
PyObject *builtinsns);
623623

624+
625+
/* "Stateless" code is a function or code object which does not rely on
626+
* external state or internal state. It may rely on arguments and
627+
* builtins, but not globals or a closure. Thus it does not rely
628+
* on __globals__ or __closure__, and a stateless function
629+
* is equivalent to its code object.
630+
*
631+
* Stateless code also does not keep any persistent state
632+
* of its own, so it can't have any executors, monitoring,
633+
* instrumentation, or "extras" (i.e. co_extra).
634+
*
635+
* Stateless code may create nested functions, including closures.
636+
* However, nested functions must themselves be stateless, except they
637+
* *can* close on the enclosing locals.
638+
*
639+
* Stateless code may return any value, including nested functions and closures.
640+
*
641+
* Stateless code that takes no arguments and doesn't return anything
642+
* may be treated like a script.
643+
*
644+
* We consider stateless code to be "portable" if it does not return any
645+
* any object that holds a reference to any of the code's locals. Thus
646+
* generators and coroutines are not portable. Likewise a function
647+
* that returns a closure is not portable. The concept of
648+
* portability is useful in cases where the code is run
649+
* in a different execution context than where
650+
* the return value will be used. */
651+
652+
PyAPI_FUNC(int) _PyCode_CheckNoInternalState(PyCodeObject *, const char **);
653+
PyAPI_FUNC(int) _PyCode_CheckNoExternalState(
654+
PyCodeObject *,
655+
_PyCode_var_counts_t *,
656+
const char **);
657+
PyAPI_FUNC(int) _PyCode_VerifyStateless(
658+
PyThreadState *,
659+
PyCodeObject *,
660+
PyObject *globalnames,
661+
PyObject *globalsns,
662+
PyObject *builtinsns);
663+
664+
PyAPI_FUNC(int) _PyCode_CheckPureFunction(PyCodeObject *, const char **);
624665
PyAPI_FUNC(int) _PyCode_ReturnsOnlyNone(PyCodeObject *);
625666

626667

Include/internal/pycore_function.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ PyFunctionObject *_PyFunction_LookupByVersion(uint32_t version, PyObject **p_cod
3535
extern PyObject *_Py_set_function_type_params(
3636
PyThreadState* unused, PyObject *func, PyObject *type_params);
3737

38+
39+
/* See pycore_code.h for explanation about what "stateless" means. */
40+
41+
PyAPI_FUNC(int)
42+
_PyFunction_VerifyStateless(PyThreadState *, PyObject *);
43+
44+
3845
#ifdef __cplusplus
3946
}
4047
#endif

Include/internal/pycore_opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_opcode_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ extern "C" {
5656

5757
#define IS_RETURN_OPCODE(opcode) \
5858
(opcode == RETURN_VALUE)
59+
#define IS_RAISE_OPCODE(opcode) \
60+
(opcode == RAISE_VARARGS || opcode == RERAISE)
5961

6062

6163
/* Flags used in the oparg for MAKE_FUNCTION */

0 commit comments

Comments
 (0)
0