Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- "Lib/test/libregrtest/**"
- "Lib/tomllib/**"
- "Misc/mypy/**"
- "Tools/build/mypy.ini"
- "Tools/build/check_extension_modules.py"
- "Tools/build/compute-changes.py"
- "Tools/build/deepfreeze.py"
Expand Down
4 changes: 2 additions & 2 deletions Doc/howto/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -990,9 +990,9 @@ Supported ``_sunder_`` names
from the final class
- :meth:`~Enum._generate_next_value_` -- used to get an appropriate value for
an enum member; may be overridden
- :meth:`~EnumType._add_alias_` -- adds a new name as an alias to an existing
- :meth:`~Enum._add_alias_` -- adds a new name as an alias to an existing
member.
- :meth:`~EnumType._add_value_alias_` -- adds a new value as an alias to an
- :meth:`~Enum._add_value_alias_` -- adds a new value as an alias to an
existing member. See `MultiValueEnum`_ for an example.

.. note::
Expand Down
53 changes: 34 additions & 19 deletions Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ Data Types
final *enum*, as well as creating the enum members, properly handling
duplicates, providing iteration over the enum class, etc.

.. versionadded:: 3.11

Before 3.11 ``EnumType`` was called ``EnumMeta``, which is still available as an alias.

.. method:: EnumType.__call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

This method is called in two different ways:
Expand Down Expand Up @@ -206,7 +210,7 @@ Data Types
>>> Color.RED.value in Color
True

.. versionchanged:: 3.12
.. versionchanged:: 3.12

Before Python 3.12, a ``TypeError`` is raised if a
non-Enum-member is used in a containment check.
Expand Down Expand Up @@ -251,20 +255,6 @@ Data Types
>>> list(reversed(Color))
[<Color.BLUE: 3>, <Color.GREEN: 2>, <Color.RED: 1>]

.. method:: EnumType._add_alias_

Adds a new name as an alias to an existing member. Raises a
:exc:`NameError` if the name is already assigned to a different member.

.. method:: EnumType._add_value_alias_

Adds a new value as an alias to an existing member. Raises a
:exc:`ValueError` if the value is already linked with a different member.

.. versionadded:: 3.11

Before 3.11 ``EnumType`` was called ``EnumMeta``, which is still available as an alias.


.. class:: Enum

Expand Down Expand Up @@ -470,6 +460,30 @@ Data Types

.. versionchanged:: 3.12 Added :ref:`enum-dataclass-support`

.. method:: Enum._add_alias_

Adds a new name as an alias to an existing member::

>>> Color.RED._add_alias_("ERROR")
>>> Color.ERROR
<Color.RED: 1>

Raises a :exc:`NameError` if the name is already assigned to a different member.

.. versionadded:: 3.13

.. method:: Enum._add_value_alias_

Adds a new value as an alias to an existing member::

>>> Color.RED._add_value_alias_(42)
>>> Color(42)
<Color.RED: 1>

Raises a :exc:`ValueError` if the value is already linked with a different member.

.. versionadded:: 3.13


.. class:: IntEnum

Expand Down Expand Up @@ -879,10 +893,6 @@ Once all the members are created it is no longer used.
Supported ``_sunder_`` names
""""""""""""""""""""""""""""

- :meth:`~EnumType._add_alias_` -- adds a new name as an alias to an existing
member.
- :meth:`~EnumType._add_value_alias_` -- adds a new value as an alias to an
existing member.
- :attr:`~Enum._name_` -- name of the member
- :attr:`~Enum._value_` -- value of the member; can be set in ``__new__``
- :meth:`~Enum._missing_` -- a lookup function used when a value is not found;
Expand All @@ -903,6 +913,11 @@ Supported ``_sunder_`` names
For :class:`Flag` classes the next value chosen will be the next highest
power-of-two.

- :meth:`~Enum._add_alias_` -- adds a new name as an alias to an existing
member.
- :meth:`~Enum._add_value_alias_` -- adds a new value as an alias to an
existing member.

- While ``_sunder_`` names are generally reserved for the further development
of the :class:`Enum` class and can not be used, some are explicitly allowed:

Expand Down
20 changes: 14 additions & 6 deletions Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5084,14 +5084,18 @@ Test_an_metho_arg_named_arg_impl(TestObj *self, int arg)
Test.__init__
*args: tuple

Varargs init method. For example, nargs is translated to PyTuple_GET_SIZE.
Varargs init method.

For example, nargs is translated to PyTuple_GET_SIZE.
[clinic start generated code]*/

PyDoc_STRVAR(Test___init____doc__,
"Test(*args)\n"
"--\n"
"\n"
"Varargs init method. For example, nargs is translated to PyTuple_GET_SIZE.");
"Varargs init method.\n"
"\n"
"For example, nargs is translated to PyTuple_GET_SIZE.");

static int
Test___init___impl(TestObj *self, PyObject *args);
Expand Down Expand Up @@ -5120,21 +5124,25 @@ Test___init__(PyObject *self, PyObject *args, PyObject *kwargs)

static int
Test___init___impl(TestObj *self, PyObject *args)
/*[clinic end generated code: output=f172425cec373cd6 input=4b8388c4e6baab6f]*/
/*[clinic end generated code: output=0e5836c40dbc2397 input=a615a4485c0fc3e2]*/

/*[clinic input]
@classmethod
Test.__new__
*args: tuple

Varargs new method. For example, nargs is translated to PyTuple_GET_SIZE.
Varargs new method.

For example, nargs is translated to PyTuple_GET_SIZE.
[clinic start generated code]*/

PyDoc_STRVAR(Test__doc__,
"Test(*args)\n"
"--\n"
"\n"
"Varargs new method. For example, nargs is translated to PyTuple_GET_SIZE.");
"Varargs new method.\n"
"\n"
"For example, nargs is translated to PyTuple_GET_SIZE.");

static PyObject *
Test_impl(PyTypeObject *type, PyObject *args);
Expand Down Expand Up @@ -5162,7 +5170,7 @@ Test(PyTypeObject *type, PyObject *args, PyObject *kwargs)

static PyObject *
Test_impl(PyTypeObject *type, PyObject *args)
/*[clinic end generated code: output=ee1e8892a67abd4a input=a8259521129cad20]*/
/*[clinic end generated code: output=e6fba0c8951882fd input=8ce30adb836aeacb]*/


/*[clinic input]
Expand Down
25 changes: 12 additions & 13 deletions Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,8 @@ _interpreters_run_func_impl(PyObject *module, PyObject *id, PyObject *func,
_interpreters.call
id: object
callable: object
args as args_obj: object(subclass_of='&PyTuple_Type', c_default='NULL') = ()
kwargs as kwargs_obj: object(subclass_of='&PyDict_Type', c_default='NULL') = {}
args: object(subclass_of='&PyTuple_Type', c_default='NULL') = ()
kwargs: object(subclass_of='&PyDict_Type', c_default='NULL') = {}
*
preserve_exc: bool = False
restrict as restricted: bool = False
Expand All @@ -1289,9 +1289,9 @@ Pass the given args and kwargs, if possible.

static PyObject *
_interpreters_call_impl(PyObject *module, PyObject *id, PyObject *callable,
PyObject *args_obj, PyObject *kwargs_obj,
int preserve_exc, int restricted)
/*[clinic end generated code: output=983ee27b3c43f6ef input=77590fdb3f519d65]*/
PyObject *args, PyObject *kwargs, int preserve_exc,
int restricted)
/*[clinic end generated code: output=b7a4a27d72df3ebc input=b026d0b212a575e6]*/
{
PyThreadState *tstate = _PyThreadState_GET();
int reqready = 1;
Expand All @@ -1302,7 +1302,7 @@ _interpreters_call_impl(PyObject *module, PyObject *id, PyObject *callable,
}

struct interp_call call = {0};
if (_interp_call_pack(tstate, &call, callable, args_obj, kwargs_obj) < 0) {
if (_interp_call_pack(tstate, &call, callable, args, kwargs) < 0) {
return NULL;
}

Expand Down Expand Up @@ -1376,25 +1376,24 @@ _interpreters_is_running_impl(PyObject *module, PyObject *id, int restricted)

/*[clinic input]
_interpreters.get_config
id as idobj: object
id: object
*
restrict as restricted: bool = False

Return a representation of the config used to initialize the interpreter.
[clinic start generated code]*/

static PyObject *
_interpreters_get_config_impl(PyObject *module, PyObject *idobj,
int restricted)
/*[clinic end generated code: output=63f81d35c2fe1387 input=aa38d50f534eb3c5]*/
_interpreters_get_config_impl(PyObject *module, PyObject *id, int restricted)
/*[clinic end generated code: output=56773353b9b7224a input=59519a01c22d96d1]*/
{
if (idobj == Py_None) {
idobj = NULL;
if (id == Py_None) {
id = NULL;
}

int reqready = 0;
PyInterpreterState *interp = \
resolve_interp(idobj, restricted, reqready, "get the config of");
resolve_interp(id, restricted, reqready, "get the config of");
if (interp == NULL) {
return NULL;
}
Expand Down
25 changes: 12 additions & 13 deletions Modules/clinic/_interpretersmodule.c.h

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

6 changes: 3 additions & 3 deletions Modules/clinic/posixmodule.c.h

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

6 changes: 3 additions & 3 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3295,15 +3295,15 @@ dir_fd, effective_ids, and follow_symlinks may not be implemented
NotImplementedError.

Note that most operations will use the effective uid/gid, therefore this
routine can be used in a suid/sgid environment to test if the invoking user
has the specified access to the path.
routine can be used in a suid/sgid environment to test if the invoking
user has the specified access to the path.

[clinic start generated code]*/

static int
os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
int effective_ids, int follow_symlinks)
/*[clinic end generated code: output=cf84158bc90b1a77 input=3ffe4e650ee3bf20]*/
/*[clinic end generated code: output=cf84158bc90b1a77 input=c33565f7584b99e4]*/
{
int return_value;

Expand Down
2 changes: 1 addition & 1 deletion Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ move_legacy_finalizer_reachable(PyGC_Head *finalizers)
* to invalidate caches (e.g. by PyType_Modified), that clearing has created
* a bug. If the weakref to the subclass is cleared before a finalizer is
* called, the cache may not be correctly invalidated. That can lead to
* segfaults since the caches can refer to deallocated objects (GH-91636
* segfaults since the caches can refer to deallocated objects (GH-135552
* is an example). Now, we delay the clear of weakrefs without callbacks
* until *after* finalizers have been executed. That means weakrefs without
* callbacks are still usable while finalizers are being executed.
Expand Down
Loading
Loading