Skip to content

Commit 8ee232c

Browse files
authored
Merge branch 'main' into fix_altgr
2 parents 69e8779 + 5d8e432 commit 8ee232c

Some content is hidden

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

45 files changed

+582
-198
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ Include/internal/pycore_time.h @pganssle @abalkin
167167
**/*imap* @python/email-team
168168
**/*poplib* @python/email-team
169169

170+
# Exclude .mailmap from being owned by @python/email-team
171+
/.mailmap
172+
170173
# Garbage collector
171174
/Modules/gcmodule.c @pablogsal
172175
/Doc/library/gc.rst @pablogsal

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# This file sets the canonical name for contributors to the repository.
22
# Documentation: https://git-scm.com/docs/gitmailmap
3+
Willow Chargin <[email protected]>
34

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ repos:
1111
args: [--exit-non-zero-on-fix]
1212
files: ^Lib/test/
1313
- id: ruff
14-
name: Run Ruff (lint) on Tools/build/check_warnings.py
14+
name: Run Ruff (lint) on Tools/build/
1515
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
16-
files: ^Tools/build/check_warnings.py
16+
files: ^Tools/build/
1717
- id: ruff
1818
name: Run Ruff (lint) on Argument Clinic
1919
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]

Doc/library/hashlib.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020

2121
--------------
2222

23-
This module implements a common interface to many different secure hash and
24-
message digest algorithms. Included are the FIPS secure hash algorithms SHA1,
25-
SHA224, SHA256, SHA384, SHA512, (defined in `the FIPS 180-4 standard`_),
26-
the SHA-3 series (defined in `the FIPS 202 standard`_) as well as RSA's MD5
27-
algorithm (defined in internet :rfc:`1321`). The terms "secure hash" and
28-
"message digest" are interchangeable. Older algorithms were called message
29-
digests. The modern term is secure hash.
23+
This module implements a common interface to many different hash algorithms.
24+
Included are the FIPS secure hash algorithms SHA224, SHA256, SHA384, SHA512,
25+
(defined in `the FIPS 180-4 standard`_), the SHA-3 series (defined in `the FIPS
26+
202 standard`_) as well as the legacy algorithms SHA1 (`formerly part of FIPS`_)
27+
and the MD5 algorithm (defined in internet :rfc:`1321`).
3028

3129
.. note::
3230

@@ -812,6 +810,7 @@ Domain Dedication 1.0 Universal:
812810
.. _the FIPS 180-4 standard: https://csrc.nist.gov/pubs/fips/180-4/upd1/final
813811
.. _the FIPS 202 standard: https://csrc.nist.gov/pubs/fips/202/final
814812
.. _HACL\* project: https://github.com/hacl-star/hacl-star
813+
.. _formerly part of FIPS: https://csrc.nist.gov/news/2023/decision-to-revise-fips-180-4
815814

816815

817816
.. _hashlib-seealso:

Doc/library/shutil.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ Directory and files operations
473473
This is also applied when *cmd* is a path that contains a directory
474474
component::
475475

476-
>> shutil.which("C:\\Python33\\python")
476+
>>> shutil.which("C:\\Python33\\python")
477477
'C:\\Python33\\python.EXE'
478478

479479
.. versionadded:: 3.3

Doc/whatsnew/3.14.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ Other language changes
479479
:func:`textwrap.dedent`.
480480
(Contributed by Jon Crall and Steven Sun in :gh:`103998`.)
481481

482+
* Improve error message when an object supporting the synchronous (resp.
483+
asynchronous) context manager protocol is entered using :keyword:`async
484+
with` (resp. :keyword:`with`) instead of :keyword:`with` (resp.
485+
:keyword:`async with`).
486+
(Contributed by Bénédikt Tran in :gh:`128398`.)
487+
482488

483489
.. _whatsnew314-pep765:
484490

@@ -819,6 +825,12 @@ json
819825
See the :ref:`JSON command-line interface <json-commandline>` documentation.
820826
(Contributed by Trey Hunner in :gh:`122873`.)
821827

828+
* By default, the output of the :ref:`JSON command-line interface <json-commandline>`
829+
is highlighted in color. This can be controlled via the
830+
:envvar:`PYTHON_COLORS` environment variable as well as the canonical
831+
|NO_COLOR|_ and |FORCE_COLOR|_ environment variables. See also
832+
:ref:`using-on-controlling-color`.
833+
(Contributed by Tomas Roun in :gh:`131952`.)
822834

823835
linecache
824836
---------

Include/internal/pycore_ceval.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ PyAPI_DATA(const conversion_func) _PyEval_ConversionFuncs[];
279279
typedef struct _special_method {
280280
PyObject *name;
281281
const char *error;
282+
const char *error_suggestion; // improved optional suggestion
282283
} _Py_SpecialMethod;
283284

284285
PyAPI_DATA(const _Py_SpecialMethod) _Py_SpecialMethods[];
@@ -309,6 +310,16 @@ PyAPI_FUNC(PyObject *) _PyEval_LoadName(PyThreadState *tstate, _PyInterpreterFra
309310
PyAPI_FUNC(int)
310311
_Py_Check_ArgsIterable(PyThreadState *tstate, PyObject *func, PyObject *args);
311312

313+
/*
314+
* Indicate whether a special method of given 'oparg' can use the (improved)
315+
* alternative error message instead. Only methods loaded by LOAD_SPECIAL
316+
* support alternative error messages.
317+
*
318+
* Symbol is exported for the JIT (see discussion on GH-132218).
319+
*/
320+
PyAPI_FUNC(int)
321+
_PyEval_SpecialMethodCanSuggest(PyObject *self, int oparg);
322+
312323
/* Bits that can be set in PyThreadState.eval_breaker */
313324
#define _PY_GIL_DROP_REQUEST_BIT (1U << 0)
314325
#define _PY_SIGNALS_PENDING_BIT (1U << 1)

Include/internal/pycore_interp_structs.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,12 @@ struct _is {
754754
* and should be placed at the beginning. */
755755
struct _ceval_state ceval;
756756

757+
/* This structure is carefully allocated so that it's correctly aligned
758+
* to avoid undefined behaviors during LOAD and STORE. The '_malloced'
759+
* field stores the allocated pointer address that will later be freed.
760+
*/
761+
void *_malloced;
762+
757763
PyInterpreterState *next;
758764

759765
int64_t id;
@@ -935,18 +941,18 @@ struct _is {
935941

936942
Py_ssize_t _interactive_src_count;
937943

938-
/* the initial PyInterpreterState.threads.head */
939-
_PyThreadStateImpl _initial_thread;
940-
// _initial_thread should be the last field of PyInterpreterState.
941-
// See https://github.com/python/cpython/issues/127117.
942-
943944
#if !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
944945
uint64_t next_stackref;
945946
_Py_hashtable_t *open_stackrefs_table;
946947
# ifdef Py_STACKREF_CLOSE_DEBUG
947948
_Py_hashtable_t *closed_stackrefs_table;
948949
# endif
949950
#endif
951+
952+
/* the initial PyInterpreterState.threads.head */
953+
_PyThreadStateImpl _initial_thread;
954+
// _initial_thread should be the last field of PyInterpreterState.
955+
// See https://github.com/python/cpython/issues/127117.
950956
};
951957

952958

Lib/json/tool.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,40 @@
55
"""
66
import argparse
77
import json
8+
import re
89
import sys
10+
from _colorize import ANSIColors, can_colorize
11+
12+
13+
# The string we are colorizing is valid JSON,
14+
# so we can use a looser but simpler regex to match
15+
# the various parts, most notably strings and numbers,
16+
# where the regex given by the spec is much more complex.
17+
_color_pattern = re.compile(r'''
18+
(?P<key>"(\\.|[^"\\])*")(?=:) |
19+
(?P<string>"(\\.|[^"\\])*") |
20+
(?P<boolean>true|false) |
21+
(?P<null>null)
22+
''', re.VERBOSE)
23+
24+
25+
_colors = {
26+
'key': ANSIColors.INTENSE_BLUE,
27+
'string': ANSIColors.BOLD_GREEN,
28+
'boolean': ANSIColors.BOLD_CYAN,
29+
'null': ANSIColors.BOLD_CYAN,
30+
}
31+
32+
33+
def _replace_match_callback(match):
34+
for key, color in _colors.items():
35+
if m := match.group(key):
36+
return f"{color}{m}{ANSIColors.RESET}"
37+
return match.group()
38+
39+
40+
def _colorize_json(json_str):
41+
return re.sub(_color_pattern, _replace_match_callback, json_str)
942

1043

1144
def main():
@@ -68,7 +101,11 @@ def main():
68101
outfile = open(options.outfile, 'w', encoding='utf-8')
69102
with outfile:
70103
for obj in objs:
71-
json.dump(obj, outfile, **dump_args)
104+
if can_colorize(file=outfile):
105+
json_str = json.dumps(obj, **dump_args)
106+
outfile.write(_colorize_json(json_str))
107+
else:
108+
json.dump(obj, outfile, **dump_args)
72109
outfile.write('\n')
73110
except ValueError as e:
74111
raise SystemExit(e)

0 commit comments

Comments
 (0)