Skip to content

Commit

Permalink
Merge branch 'main' into pythongh-129027
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasreddy committed Jan 20, 2025
2 parents fc4d384 + 8ceb6cb commit aef2b2d
Show file tree
Hide file tree
Showing 127 changed files with 3,393 additions and 3,651 deletions.
2,856 changes: 1,555 additions & 1,301 deletions Doc/c-api/init_config.rst

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1375,3 +1375,7 @@ Removed

* Creating :c:data:`immutable types <Py_TPFLAGS_IMMUTABLETYPE>` with mutable
bases was deprecated since 3.12 and now raises a :exc:`TypeError`.

* Remove the private ``_Py_InitializeMain()`` function. It was a
:term:`provisional API` added to Python 3.8 by :pep:`587`.
(Contributed by Victor Stinner in :gh:`129033`.)
3 changes: 0 additions & 3 deletions Include/cpython/pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ PyAPI_FUNC(PyStatus) Py_PreInitializeFromArgs(
PyAPI_FUNC(PyStatus) Py_InitializeFromConfig(
const PyConfig *config);

// Python 3.8 provisional API (PEP 587)
PyAPI_FUNC(PyStatus) _Py_InitializeMain(void);

PyAPI_FUNC(int) Py_RunMain(void);


Expand Down
37 changes: 0 additions & 37 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,43 +341,6 @@ extern void _PyInterpreterState_SetWhence(

extern const PyConfig* _PyInterpreterState_GetConfig(PyInterpreterState *interp);

// Get a copy of the current interpreter configuration.
//
// Return 0 on success. Raise an exception and return -1 on error.
//
// The caller must initialize 'config', using PyConfig_InitPythonConfig()
// for example.
//
// Python must be preinitialized to call this method.
// The caller must hold the GIL.
//
// Once done with the configuration, PyConfig_Clear() must be called to clear
// it.
//
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC(int) _PyInterpreterState_GetConfigCopy(
struct PyConfig *config);

// Set the configuration of the current interpreter.
//
// This function should be called during or just after the Python
// initialization.
//
// Update the sys module with the new configuration. If the sys module was
// modified directly after the Python initialization, these changes are lost.
//
// Some configuration like faulthandler or warnoptions can be updated in the
// configuration, but don't reconfigure Python (don't enable/disable
// faulthandler and don't reconfigure warnings filters).
//
// Return 0 on success. Raise an exception and return -1 on error.
//
// The configuration should come from _PyInterpreterState_GetConfigCopy().
//
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC(int) _PyInterpreterState_SetConfig(
const struct PyConfig *config);


/*
Runtime Feature Flags
Expand Down
13 changes: 13 additions & 0 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,19 @@ PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
// See also PyInterpreterState_Get() and _PyInterpreterState_GET().
extern PyInterpreterState* _PyGILState_GetInterpreterStateUnsafe(void);

#ifndef NDEBUG
/* Modern equivalent of assert(PyGILState_Check()) */
static inline void
_Py_AssertHoldsTstateFunc(const char *func)
{
PyThreadState *tstate = _PyThreadState_GET();
_Py_EnsureFuncTstateNotNULL(func, tstate);
}
#define _Py_AssertHoldsTstate() _Py_AssertHoldsTstateFunc(__func__)
#else
#define _Py_AssertHoldsTstate()
#endif

#ifdef __cplusplus
}
#endif
Expand Down
15 changes: 9 additions & 6 deletions Lib/_colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ class ANSIColors:
setattr(NoColors, attr, "")


def get_colors(colorize: bool = False) -> ANSIColors:
if colorize or can_colorize():
def get_colors(colorize: bool = False, *, file=None) -> ANSIColors:
if colorize or can_colorize(file=file):
return ANSIColors()
else:
return NoColors


def can_colorize() -> bool:
def can_colorize(*, file=None) -> bool:
if file is None:
file = sys.stdout

if not sys.flags.ignore_environment:
if os.environ.get("PYTHON_COLORS") == "0":
return False
Expand All @@ -49,7 +52,7 @@ def can_colorize() -> bool:
if os.environ.get("TERM") == "dumb":
return False

if not hasattr(sys.stderr, "fileno"):
if not hasattr(file, "fileno"):
return False

if sys.platform == "win32":
Expand All @@ -62,6 +65,6 @@ def can_colorize() -> bool:
return False

try:
return os.isatty(sys.stderr.fileno())
return os.isatty(file.fileno())
except io.UnsupportedOperation:
return sys.stderr.isatty()
return file.isatty()
2 changes: 1 addition & 1 deletion Lib/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ def out(s):
save_displayhook = sys.displayhook
sys.displayhook = sys.__displayhook__
saved_can_colorize = _colorize.can_colorize
_colorize.can_colorize = lambda: False
_colorize.can_colorize = lambda *args, **kwargs: False
color_variables = {"PYTHON_COLORS": None, "FORCE_COLOR": None}
for key in color_variables:
color_variables[key] = os.environ.pop(key, None)
Expand Down
3 changes: 3 additions & 0 deletions Lib/sysconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,9 @@ def expand_makefile_vars(s, vars):
"""
import re

_findvar1_rx = r"\$\(([A-Za-z][A-Za-z0-9_]*)\)"
_findvar2_rx = r"\${([A-Za-z][A-Za-z0-9_]*)}"

# This algorithm does multiple expansion, so if vars['foo'] contains
# "${bar}", it will expand ${foo} to ${bar}, and then expand
# ${bar}... and so forth. This is fine as long as 'vars' comes from
Expand Down
Loading

0 comments on commit aef2b2d

Please sign in to comment.