Skip to content

Commit 53dcb79

Browse files
committed
Merge branch 'main' into pythongh-102613-remove-selector-classes
2 parents d5c86c6 + dcdc90d commit 53dcb79

File tree

137 files changed

+13020
-5506
lines changed

Some content is hidden

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

137 files changed

+13020
-5506
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ configure* @erlend-aasland @corona10
2222
**/*hamt* @1st1
2323
Objects/set* @rhettinger
2424
Objects/dict* @methane @markshannon
25+
Objects/typevarobject.c @JelleZijlstra
2526
Objects/type* @markshannon
2627
Objects/codeobject.c @markshannon
2728
Objects/frameobject.c @markshannon
@@ -33,6 +34,7 @@ Python/flowgraph.c @markshannon @iritkatriel
3334
Python/ast_opt.c @isidentical
3435
Lib/test/test_patma.py @brandtbucher
3536
Lib/test/test_peepholer.py @brandtbucher
37+
Lib/test/test_type_*.py @JelleZijlstra
3638

3739
# Exceptions
3840
Lib/traceback.py @iritkatriel

Doc/c-api/frame.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,38 @@ See also :ref:`Reflection <reflection>`.
130130
.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame)
131131
132132
Return the line number that *frame* is currently executing.
133+
134+
135+
136+
Internal Frames
137+
---------------
138+
139+
Unless using :pep:`523`, you will not need this.
140+
141+
.. c:struct:: _PyInterpreterFrame
142+
143+
The interpreter's internal frame representation.
144+
145+
.. versionadded:: 3.11
146+
147+
.. c:function:: PyObject* PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame);
148+
149+
Return a :term:`strong reference` to the code object for the frame.
150+
151+
.. versionadded:: 3.12
152+
153+
154+
.. c:function:: int PyUnstable_InterpreterFrame_GetLasti(struct _PyInterpreterFrame *frame);
155+
156+
Return the byte offset into the last executed instruction.
157+
158+
.. versionadded:: 3.12
159+
160+
161+
.. c:function:: int PyUnstable_InterpreterFrame_GetLine(struct _PyInterpreterFrame *frame);
162+
163+
Return the currently executing line number, or -1 if there is no line number.
164+
165+
.. versionadded:: 3.12
166+
167+

Doc/library/ast.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,7 @@ Function and class definitions
17241724
body=[
17251725
FunctionDef(
17261726
name='f',
1727+
typeparams=[],
17271728
args=arguments(
17281729
posonlyargs=[],
17291730
args=[
@@ -1847,6 +1848,7 @@ Function and class definitions
18471848
body=[
18481849
ClassDef(
18491850
name='Foo',
1851+
typeparams=[],
18501852
bases=[
18511853
Name(id='base1', ctx=Load()),
18521854
Name(id='base2', ctx=Load())],
@@ -1885,6 +1887,7 @@ Async and await
18851887
body=[
18861888
AsyncFunctionDef(
18871889
name='f',
1890+
typeparams=[],
18881891
args=arguments(
18891892
posonlyargs=[],
18901893
args=[],

Doc/library/http.client.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,17 @@ HTTPConnection Objects
394394
one will be automatically generated and transmitted if not provided in
395395
the headers argument.
396396

397+
398+
.. method:: HTTPConnection.get_proxy_response_headers()
399+
400+
Returns a dictionary with the headers of the response received from
401+
the proxy server to the CONNECT request.
402+
403+
If the CONNECT request was not sent, the method returns an empty dictionary.
404+
405+
.. versionadded:: 3.12
406+
407+
397408
.. method:: HTTPConnection.connect()
398409

399410
Connect to the server specified when the object was created. By default,

Doc/library/logging.config.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ in :mod:`logging` itself) and defining handlers which are declared either in
8787
provides a mechanism to present the choices and load the chosen
8888
configuration).
8989

90+
It will raise :exc:`FileNotFoundError` if the file
91+
doesn't exist and :exc:`ValueError` if the file is invalid or
92+
empty.
93+
9094
:param fname: A filename, or a file-like object, or an instance derived
9195
from :class:`~configparser.RawConfigParser`. If a
9296
``RawConfigParser``-derived instance is passed, it is used as
@@ -111,7 +115,7 @@ in :mod:`logging` itself) and defining handlers which are declared either in
111115
they or their ancestors are explicitly named
112116
in the logging configuration.
113117

114-
:param encoding: The encoding used to open file when *fname* is filename.
118+
:param encoding: The encoding used to open file when *fname* is filename.
115119

116120
.. versionchanged:: 3.4
117121
An instance of a subclass of :class:`~configparser.RawConfigParser` is
@@ -126,6 +130,10 @@ in :mod:`logging` itself) and defining handlers which are declared either in
126130
.. versionadded:: 3.10
127131
The *encoding* parameter is added.
128132

133+
.. versionadded:: 3.12
134+
An exception will be thrown if the provided file
135+
doesn't exist or is invalid or empty.
136+
129137
.. function:: listen(port=DEFAULT_LOGGING_CONFIG_PORT, verify=None)
130138

131139
Starts up a socket server on the specified port, and listens for new

Doc/library/pathlib.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ Pure paths provide the following methods and properties:
546546
PureWindowsPath('c:/Program Files')
547547

548548

549-
.. method:: PurePath.match(pattern)
549+
.. method:: PurePath.match(pattern, *, case_sensitive=None)
550550

551551
Match this path against the provided glob-style pattern. Return ``True``
552552
if matching is successful, ``False`` otherwise.
@@ -576,6 +576,11 @@ Pure paths provide the following methods and properties:
576576
>>> PureWindowsPath('b.py').match('*.PY')
577577
True
578578

579+
Set *case_sensitive* to ``True`` or ``False`` to override this behaviour.
580+
581+
.. versionadded:: 3.12
582+
The *case_sensitive* argument.
583+
579584

580585
.. method:: PurePath.relative_to(other, walk_up=False)
581586

Doc/library/urllib.parse.rst

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ or on combining URL components into a URL string.
159159
ParseResult(scheme='http', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html',
160160
params='', query='', fragment='')
161161

162+
.. warning::
163+
164+
:func:`urlparse` does not perform validation. See :ref:`URL parsing
165+
security <url-parsing-security>` for details.
162166

163167
.. versionchanged:: 3.2
164168
Added IPv6 URL parsing capabilities.
@@ -324,8 +328,14 @@ or on combining URL components into a URL string.
324328
``#``, ``@``, or ``:`` will raise a :exc:`ValueError`. If the URL is
325329
decomposed before parsing, no error will be raised.
326330

327-
Following the `WHATWG spec`_ that updates RFC 3986, ASCII newline
328-
``\n``, ``\r`` and tab ``\t`` characters are stripped from the URL.
331+
Following some of the `WHATWG spec`_ that updates RFC 3986, leading C0
332+
control and space characters are stripped from the URL. ``\n``,
333+
``\r`` and tab ``\t`` characters are removed from the URL at any position.
334+
335+
.. warning::
336+
337+
:func:`urlsplit` does not perform validation. See :ref:`URL parsing
338+
security <url-parsing-security>` for details.
329339

330340
.. versionchanged:: 3.6
331341
Out-of-range port numbers now raise :exc:`ValueError`, instead of
@@ -338,6 +348,9 @@ or on combining URL components into a URL string.
338348
.. versionchanged:: 3.10
339349
ASCII newline and tab characters are stripped from the URL.
340350

351+
.. versionchanged:: 3.12
352+
Leading WHATWG C0 control and space characters are stripped from the URL.
353+
341354
.. _WHATWG spec: https://url.spec.whatwg.org/#concept-basic-url-parser
342355

343356
.. function:: urlunsplit(parts)
@@ -414,6 +427,35 @@ or on combining URL components into a URL string.
414427
or ``scheme://host/path``). If *url* is not a wrapped URL, it is returned
415428
without changes.
416429

430+
.. _url-parsing-security:
431+
432+
URL parsing security
433+
--------------------
434+
435+
The :func:`urlsplit` and :func:`urlparse` APIs do not perform **validation** of
436+
inputs. They may not raise errors on inputs that other applications consider
437+
invalid. They may also succeed on some inputs that might not be considered
438+
URLs elsewhere. Their purpose is for practical functionality rather than
439+
purity.
440+
441+
Instead of raising an exception on unusual input, they may instead return some
442+
component parts as empty strings. Or components may contain more than perhaps
443+
they should.
444+
445+
We recommend that users of these APIs where the values may be used anywhere
446+
with security implications code defensively. Do some verification within your
447+
code before trusting a returned component part. Does that ``scheme`` make
448+
sense? Is that a sensible ``path``? Is there anything strange about that
449+
``hostname``? etc.
450+
451+
What constitutes a URL is not universally well defined. Different applications
452+
have different needs and desired constraints. For instance the living `WHATWG
453+
spec`_ describes what user facing web clients such as a web browser require.
454+
While :rfc:`3986` is more general. These functions incorporate some aspects of
455+
both, but cannot be claimed compliant with either. The APIs and existing user
456+
code with expectations on specific behaviors predate both standards leading us
457+
to be very cautious about making API behavior changes.
458+
417459
.. _parsing-ascii-encoded-bytes:
418460

419461
Parsing ASCII Encoded Bytes

Doc/whatsnew/3.12.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ pathlib
395395
* Add :meth:`pathlib.Path.is_junction` as a proxy to :func:`os.path.isjunction`.
396396
(Contributed by Charles Machalow in :gh:`99547`.)
397397

398+
* Add *case_sensitive* optional parameter to :meth:`pathlib.Path.glob`,
399+
:meth:`pathlib.Path.rglob` and :meth:`pathlib.PurePath.match` for matching
400+
the path's case sensitivity, allowing for more precise control over the matching process.
398401

399402
dis
400403
---

Grammar/python.gram

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ simple_stmts[asdl_stmt_seq*]:
112112
# will throw a SyntaxError.
113113
simple_stmt[stmt_ty] (memo):
114114
| assignment
115+
| &"type" type_alias
115116
| e=star_expressions { _PyAST_Expr(e, EXTRA) }
116117
| &'return' return_stmt
117118
| &('import' | 'from') import_stmt
@@ -252,8 +253,8 @@ class_def[stmt_ty]:
252253

253254
class_def_raw[stmt_ty]:
254255
| invalid_class_def_raw
255-
| 'class' a=NAME b=['(' z=[arguments] ')' { z }] ':' c=block {
256-
_PyAST_ClassDef(a->v.Name.id,
256+
| 'class' a=NAME t=[type_params] b=['(' z=[arguments] ')' { z }] ':' c=block {
257+
_PyAST_ClassDef(a->v.Name.id, t,
257258
(b) ? ((expr_ty) b)->v.Call.args : NULL,
258259
(b) ? ((expr_ty) b)->v.Call.keywords : NULL,
259260
c, NULL, EXTRA) }
@@ -267,16 +268,16 @@ function_def[stmt_ty]:
267268

268269
function_def_raw[stmt_ty]:
269270
| invalid_def_raw
270-
| 'def' n=NAME &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
271-
_PyAST_FunctionDef(n->v.Name.id,
271+
| 'def' n=NAME t=[type_params] &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
272+
_PyAST_FunctionDef(n->v.Name.id, t,
272273
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
273274
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA) }
274-
| ASYNC 'def' n=NAME &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
275+
| ASYNC 'def' n=NAME t=[type_params] &&'(' params=[params] ')' a=['->' z=expression { z }] &&':' tc=[func_type_comment] b=block {
275276
CHECK_VERSION(
276277
stmt_ty,
277278
5,
278279
"Async functions are",
279-
_PyAST_AsyncFunctionDef(n->v.Name.id,
280+
_PyAST_AsyncFunctionDef(n->v.Name.id, t,
280281
(params) ? params : CHECK(arguments_ty, _PyPegen_empty_arguments(p)),
281282
b, NULL, a, NEW_TYPE_COMMENT(p, tc), EXTRA)
282283
) }
@@ -628,6 +629,39 @@ keyword_patterns[asdl_seq*]:
628629
keyword_pattern[KeyPatternPair*]:
629630
| arg=NAME '=' value=pattern { _PyPegen_key_pattern_pair(p, arg, value) }
630631

632+
# Type statement
633+
# ---------------
634+
635+
type_alias[stmt_ty]:
636+
| "type" n=NAME t=[type_params] '=' b=expression {
637+
CHECK_VERSION(stmt_ty, 12, "Type statement is",
638+
_PyAST_TypeAlias(CHECK(expr_ty, _PyPegen_set_expr_context(p, n, Store)), t, b, EXTRA)) }
639+
640+
# Type parameter declaration
641+
# --------------------------
642+
643+
type_params[asdl_typeparam_seq*]: '[' t=type_param_seq ']' {
644+
CHECK_VERSION(asdl_typeparam_seq *, 12, "Type parameter lists are", t) }
645+
646+
type_param_seq[asdl_typeparam_seq*]: a[asdl_typeparam_seq*]=','.type_param+ [','] { a }
647+
648+
type_param[typeparam_ty] (memo):
649+
| a=NAME b=[type_param_bound] { _PyAST_TypeVar(a->v.Name.id, b, EXTRA) }
650+
| '*' a=NAME colon=":" e=expression {
651+
RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
652+
? "cannot use constraints with TypeVarTuple"
653+
: "cannot use bound with TypeVarTuple")
654+
}
655+
| '*' a=NAME { _PyAST_TypeVarTuple(a->v.Name.id, EXTRA) }
656+
| '**' a=NAME colon=":" e=expression {
657+
RAISE_SYNTAX_ERROR_STARTING_FROM(colon, e->kind == Tuple_kind
658+
? "cannot use constraints with ParamSpec"
659+
: "cannot use bound with ParamSpec")
660+
}
661+
| '**' a=NAME { _PyAST_ParamSpec(a->v.Name.id, EXTRA) }
662+
663+
type_param_bound[expr_ty]: ":" e=expression { e }
664+
631665
# EXPRESSIONS
632666
# -----------
633667

Include/cpython/frameobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
3535

3636
/* Returns the code object of the frame (strong reference).
3737
* Does not raise an exception. */
38-
PyAPI_FUNC(PyCodeObject *) PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame);
38+
PyAPI_FUNC(PyObject *) PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame);
3939

4040
/* Returns a byte ofsset into the last executed instruction.
4141
* Does not raise an exception. */

0 commit comments

Comments
 (0)