Skip to content

Commit b1bb3a7

Browse files
committed
Merge branch 'main' into 709funconly
* main: (26 commits) pythonGH-101520: Move tracemalloc functionality into core, leaving interface in Modules. (python#104508) typing: Add more tests for TypeVar (python#104571) pythongh-104572: Improve error messages for invalid constructs in PEP 695 contexts (python#104573) typing: Use PEP 695 syntax in typing.py (python#104553) pythongh-102153: Start stripping C0 control and space chars in `urlsplit` (python#102508) pythongh-104469: Update README.txt for _testcapi (pythongh-104529) pythonGH-103092: isolate `_elementtree` (python#104561) pythongh-104050: Add typing to Argument Clinic converters (python#104547) pythonGH-103906: Remove immortal refcounting in the interpreter (pythonGH-103909) pythongh-87474: Fix file descriptor leaks in subprocess.Popen (python#96351) pythonGH-103092: isolate `pyexpat` (python#104506) pythongh-75367: Fix data descriptor detection in inspect.getattr_static (python#104517) pythongh-104050: Add more annotations to `Tools/clinic.py` (python#104544) pythongh-104555: Fix isinstance() and issubclass() for runtime-checkable protocols that use PEP 695 (python#104556) pythongh-103865: add monitoring support to LOAD_SUPER_ATTR (python#103866) CODEOWNERS: Assign new PEP 695 files to myself (python#104551) pythonGH-104510: Fix refleaks in `_io` base types (python#104516) pythongh-104539: Fix indentation error in logging.config.rst (python#104545) pythongh-104050: Don't star-import 'types' in Argument Clinic (python#104543) pythongh-104050: Add basic typing to CConverter in clinic.py (python#104538) ...
2 parents 2c47a75 + f7df173 commit b1bb3a7

File tree

98 files changed

+12080
-5307
lines changed

Some content is hidden

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

98 files changed

+12080
-5307
lines changed

.github/CODEOWNERS

+2
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/library/ast.rst

+3
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

+11
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ in :mod:`logging` itself) and defining handlers which are declared either in
111111
they or their ancestors are explicitly named
112112
in the logging configuration.
113113

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

116116
.. versionchanged:: 3.4
117117
An instance of a subclass of :class:`~configparser.RawConfigParser` is

Doc/library/urllib.parse.rst

+44-2
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

Grammar/python.gram

+40-6
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/funcobject.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef struct {
4141
PyObject *func_weakreflist; /* List of weak references */
4242
PyObject *func_module; /* The __module__ attribute, can be anything */
4343
PyObject *func_annotations; /* Annotations, a dict or NULL */
44+
PyObject *func_typeparams; /* Tuple of active type variables or NULL */
4445
vectorcallfunc vectorcall;
4546
/* Version number for use by specializer.
4647
* Can set to non-zero when we want to specialize.

0 commit comments

Comments
 (0)