Skip to content

Commit

Permalink
Merge branch 'main' into gsallam/main
Browse files Browse the repository at this point in the history
* main: (30 commits)
  pythongh-103987: fix several crashes in mmap module (python#103990)
  docs: fix wrong indentation causing rendering error in dis page (python#104661)
  pythongh-94906: Support multiple steps in math.nextafter (python#103881)
  pythongh-104472: Skip `test_subprocess.ProcessTestCase.test_empty_env` if ASAN is enabled (python#104667)
  pythongh-103839: Allow building Tkinter against Tcl 8.7 without external libtommath (pythonGH-103842)
  pythongh-85984: New additions and improvements to the tty library. (python#101832)
  pythongh-104659: Consolidate python examples in enum documentation (python#104665)
  pythongh-92248: Deprecate `type`, `choices`, `metavar` parameters of `argparse.BooleanOptionalAction` (python#103678)
  pythongh-104645: fix error handling in marshal tests (python#104646)
  pythongh-104600: Make type.__type_params__ writable (python#104634)
  pythongh-104602: Add additional test for listcomp with lambda (python#104639)
  pythongh-104640: Disallow walrus in comprehension within type scopes (python#104641)
  pythongh-103921: Rename "type" header in argparse docs (python#104654)
  Improve readability of `typing._ProtocolMeta.__instancecheck__` (python#104649)
  pythongh-96522: Fix deadlock in pty.spawn (python#96639)
  pythonGH-102818: Do not call `PyTraceBack_Here` in sys.settrace trampoline.  (pythonGH-104579)
  pythonGH-103545: Add macOS specific constants for ``os.setpriority`` to ``os`` (python#104606)
  pythongh-104623: Update macOS installer to SQLite 3.42.0 (pythonGH-104624)
  pythongh-104619: never leak comprehension locals to outer locals() (python#104637)
  pythongh-104602: ensure all cellvars are known up front (python#104603)
  ...
  • Loading branch information
carljm committed May 20, 2023
2 parents 6585f32 + ceaa4c3 commit ea5965a
Show file tree
Hide file tree
Showing 80 changed files with 1,254 additions and 299 deletions.
30 changes: 15 additions & 15 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ the extracted data in a :class:`argparse.Namespace` object::
Quick Links for add_argument()
------------------------------

====================== =========================================================== ==========================================================================================================================
Name Description Values
====================== =========================================================== ==========================================================================================================================
action_ Specify how an argument should be handled ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
choices_ Limit values to a specific set of choices ``['foo', 'bar']``, ``range(1, 10)``, or :class:`~collections.abc.Container` instance
const_ Store a constant value
default_ Default value used when an argument is not provided Defaults to ``None``
dest_ Specify the attribute name used in the result namespace
help_ Help message for an argument
metavar_ Alternate display name for the argument as shown in help
nargs_ Number of times the argument can be used :class:`int`, ``'?'``, ``'*'``, or ``'+'``
required_ Indicate whether an argument is required or optional ``True`` or ``False``
type_ Automatically convert an argument to the given type :class:`int`, :class:`float`, ``argparse.FileType('w')``, or callable function
====================== =========================================================== ==========================================================================================================================
============================ =========================================================== ==========================================================================================================================
Name Description Values
============================ =========================================================== ==========================================================================================================================
action_ Specify how an argument should be handled ``'store'``, ``'store_const'``, ``'store_true'``, ``'append'``, ``'append_const'``, ``'count'``, ``'help'``, ``'version'``
choices_ Limit values to a specific set of choices ``['foo', 'bar']``, ``range(1, 10)``, or :class:`~collections.abc.Container` instance
const_ Store a constant value
default_ Default value used when an argument is not provided Defaults to ``None``
dest_ Specify the attribute name used in the result namespace
help_ Help message for an argument
metavar_ Alternate display name for the argument as shown in help
nargs_ Number of times the argument can be used :class:`int`, ``'?'``, ``'*'``, or ``'+'``
required_ Indicate whether an argument is required or optional ``True`` or ``False``
:ref:`type <argparse-type>` Automatically convert an argument to the given type :class:`int`, :class:`float`, ``argparse.FileType('w')``, or callable function
============================ =========================================================== ==========================================================================================================================


Example
Expand Down Expand Up @@ -1132,7 +1132,7 @@ command-line argument was not present::
Namespace(foo='1')


.. _type:
.. _argparse-type:

type
^^^^
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ not have to be) the original ``STACK[-2]``.

.. versionadded:: 3.8

.. versionchanged:: 3.11
Exception representation on the stack now consist of one, not three, items.
.. versionchanged:: 3.11
Exception representation on the stack now consist of one, not three, items.


.. opcode:: CLEANUP_THROW
Expand Down
12 changes: 6 additions & 6 deletions Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -406,18 +406,18 @@ Data Types
with an *IntEnum* member, the resulting value loses its enumeration status.

>>> from enum import IntEnum
>>> class Numbers(IntEnum):
>>> class Number(IntEnum):
... ONE = 1
... TWO = 2
... THREE = 3
...
>>> Numbers.THREE
<Numbers.THREE: 3>
>>> Numbers.ONE + Numbers.TWO
>>> Number.THREE
<Number.THREE: 3>
>>> Number.ONE + Number.TWO
3
>>> Numbers.THREE + 5
>>> Number.THREE + 5
8
>>> Numbers.THREE == 3
>>> Number.THREE == 3
True

.. note::
Expand Down
9 changes: 6 additions & 3 deletions Doc/library/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ Number-theoretic and representation functions
of *x* and are floats.


.. function:: nextafter(x, y)
.. function:: nextafter(x, y, steps=1)

Return the next floating-point value after *x* towards *y*.
Return the floating-point value *steps* steps after *x* towards *y*.

If *x* is equal to *y*, return *y*.
If *x* is equal to *y*, return *y*, unless *steps* is zero.

Examples:

Expand All @@ -239,6 +239,9 @@ Number-theoretic and representation functions

See also :func:`math.ulp`.

.. versionchanged:: 3.12
Added the *steps* argument.

.. versionadded:: 3.9

.. function:: perm(n, k=None)
Expand Down
11 changes: 11 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,17 @@ process and user.
.. versionadded:: 3.3


.. data:: PRIO_DARWIN_THREAD
PRIO_DARWIN_PROCESS
PRIO_DARWIN_BG
PRIO_DARWIN_NONUI

Parameters for the :func:`getpriority` and :func:`setpriority` functions.

.. availability:: macOS

.. versionadded:: 3.12

.. function:: getresuid()

Return a tuple (ruid, euid, suid) denoting the current process's
Expand Down
7 changes: 6 additions & 1 deletion Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ Pure paths provide the following methods and properties:
PureWindowsPath('c:/Program Files')


.. method:: PurePath.match(pattern)
.. method:: PurePath.match(pattern, *, case_sensitive=None)

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

Set *case_sensitive* to ``True`` or ``False`` to override this behaviour.

.. versionadded:: 3.12
The *case_sensitive* argument.


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

Expand Down
22 changes: 20 additions & 2 deletions Doc/library/tty.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,36 @@ Because it requires the :mod:`termios` module, it will work only on Unix.
The :mod:`tty` module defines the following functions:


.. function:: cfmakeraw(mode)

Convert the tty attribute list *mode*, which is a list like the one returned
by :func:`termios.tcgetattr`, to that of a tty in raw mode.

.. versionadded:: 3.12


.. function:: cfmakecbreak(mode)

Convert the tty attribute list *mode*, which is a list like the one returned
by :func:`termios.tcgetattr`, to that of a tty in cbreak mode.

.. versionadded:: 3.12


.. function:: setraw(fd, when=termios.TCSAFLUSH)

Change the mode of the file descriptor *fd* to raw. If *when* is omitted, it
defaults to :const:`termios.TCSAFLUSH`, and is passed to
:func:`termios.tcsetattr`.
:func:`termios.tcsetattr`. The return value of :func:`termios.tcgetattr`
is saved before setting *fd* to raw mode; this value is returned.


.. function:: setcbreak(fd, when=termios.TCSAFLUSH)

Change the mode of file descriptor *fd* to cbreak. If *when* is omitted, it
defaults to :const:`termios.TCSAFLUSH`, and is passed to
:func:`termios.tcsetattr`.
:func:`termios.tcsetattr`. The return value of :func:`termios.tcgetattr`
is saved before setting *fd* to cbreak mode; this value is returned.


.. seealso::
Expand Down
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ pathlib
* Add :meth:`pathlib.Path.is_junction` as a proxy to :func:`os.path.isjunction`.
(Contributed by Charles Machalow in :gh:`99547`.)

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

dis
---
Expand Down Expand Up @@ -867,6 +870,11 @@ Pending Removal in Python 3.14
* The *onerror* argument of :func:`shutil.rmtree` is deprecated in 3.12,
and will be removed in 3.14.

* The *type*, *choices*, and *metavar* parameters
of :class:`!argparse.BooleanOptionalAction` are deprecated
and will be removed in 3.14.
(Contributed by Nikita Sobolev in :gh:`92248`.)

* :func:`pkgutil.find_loader` and :func:`pkgutil.get_loader`
now raise :exc:`DeprecationWarning`;
use :func:`importlib.util.find_spec` instead.
Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ PyAPI_FUNC(PyObject*) _PyCompile_CodeGen(

PyAPI_FUNC(PyObject*) _PyCompile_OptimizeCfg(
PyObject *instructions,
PyObject *consts);
PyObject *consts,
int nlocals);

PyAPI_FUNC(PyCodeObject*)
_PyCompile_Assemble(_PyCompile_CodeUnitMetadata *umd, PyObject *filename,
Expand Down
1 change: 0 additions & 1 deletion Include/internal/pycore_global_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct _Py_interp_cached_objects {
PyTypeObject *paramspec_type;
PyTypeObject *paramspecargs_type;
PyTypeObject *paramspeckwargs_type;
PyTypeObject *typealias_type;
};

#define _Py_INTERP_STATIC_OBJECT(interp, NAME) \
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(newline)
STRUCT_FOR_ID(newlines)
STRUCT_FOR_ID(next)
STRUCT_FOR_ID(nlocals)
STRUCT_FOR_ID(node_depth)
STRUCT_FOR_ID(node_offset)
STRUCT_FOR_ID(ns)
Expand Down Expand Up @@ -680,6 +681,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(stdin)
STRUCT_FOR_ID(stdout)
STRUCT_FOR_ID(step)
STRUCT_FOR_ID(steps)
STRUCT_FOR_ID(store_name)
STRUCT_FOR_ID(strategy)
STRUCT_FOR_ID(strftime)
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Include/internal/pycore_symtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,15 @@ extern PyObject* _Py_Mangle(PyObject *p, PyObject *name);
#define DEF_ANNOT 2<<7 /* this name is annotated */
#define DEF_COMP_ITER 2<<8 /* this name is a comprehension iteration variable */
#define DEF_TYPE_PARAM 2<<9 /* this name is a type parameter */
#define DEF_COMP_CELL 2<<10 /* this name is a cell in an inlined comprehension */

#define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)

/* GLOBAL_EXPLICIT and GLOBAL_IMPLICIT are used internally by the symbol
table. GLOBAL is returned from PyST_GetScope() for either of them.
It is stored in ste_symbols at bits 12-15.
It is stored in ste_symbols at bits 13-16.
*/
#define SCOPE_OFFSET 11
#define SCOPE_OFFSET 12
#define SCOPE_MASK (DEF_GLOBAL | DEF_LOCAL | DEF_PARAM | DEF_NONLOCAL)

#define LOCAL 1
Expand Down
2 changes: 2 additions & 0 deletions Include/internal/pycore_typevarobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extern PyObject *_Py_subscript_generic(PyThreadState *, PyObject *);
extern int _Py_initialize_generic(PyInterpreterState *);
extern void _Py_clear_generic_types(PyInterpreterState *);

extern PyTypeObject _PyTypeAlias_Type;

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,19 @@ def __call__(self, parser, namespace, values, option_string=None):
raise NotImplementedError(_('.__call__() not defined'))


# FIXME: remove together with `BooleanOptionalAction` deprecated arguments.
_deprecated_default = object()

class BooleanOptionalAction(Action):
def __init__(self,
option_strings,
dest,
default=None,
type=None,
choices=None,
type=_deprecated_default,
choices=_deprecated_default,
required=False,
help=None,
metavar=None):
metavar=_deprecated_default):

_option_strings = []
for option_string in option_strings:
Expand All @@ -902,6 +905,24 @@ def __init__(self,
option_string = '--no-' + option_string[2:]
_option_strings.append(option_string)

# We need `_deprecated` special value to ban explicit arguments that
# match default value. Like:
# parser.add_argument('-f', action=BooleanOptionalAction, type=int)
for field_name in ('type', 'choices', 'metavar'):
if locals()[field_name] is not _deprecated_default:
warnings._deprecated(
field_name,
"{name!r} is deprecated as of Python 3.12 and will be "
"removed in Python {remove}.",
remove=(3, 14))

if type is _deprecated_default:
type = None
if choices is _deprecated_default:
choices = None
if metavar is _deprecated_default:
metavar = None

super().__init__(
option_strings=_option_strings,
dest=dest,
Expand Down
2 changes: 1 addition & 1 deletion Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# wrapper functions that can handle naive introspection

WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__qualname__', '__doc__',
'__annotations__')
'__annotations__', '__type_params__')
WRAPPER_UPDATES = ('__dict__',)
def update_wrapper(wrapper,
wrapped,
Expand Down
Loading

0 comments on commit ea5965a

Please sign in to comment.