Skip to content

Commit

Permalink
Post-merge cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Oct 11, 2023
1 parent c363de7 commit 98b634a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5224,7 +5224,7 @@ enables cleaner type hinting syntax compared to subscripting :class:`typing.Unio
The user-exposed type for the union object can be accessed from
:class:`typing.Union` and used for :func:`isinstance` checks::

>>> import types
>>> import typing
>>> isinstance(int | str, typing.Union)
True

Expand Down
3 changes: 2 additions & 1 deletion Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This module provides runtime support for type hints. For the original
specification of the typing system, see :pep:`484`. For a simplified
introduction to type hints, see :pep:`483`.


The function below takes and returns a string and is annotated as follows::

def greeting(name: str) -> str:
Expand Down Expand Up @@ -1063,7 +1064,7 @@ Special forms
These can be used as types in annotations. They all support subscription using
``[]``, but each has a unique syntax.

.. data:: Union
.. class:: Union

Union type; ``Union[X, Y]`` is equivalent to ``X | Y`` and means either X or Y.

Expand Down
5 changes: 1 addition & 4 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,11 +1798,8 @@ def test_cannot_subclass(self):
r"type 'typing\.Union' is not an acceptable base type"):
class C(Union):
pass
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
class D(type(Union)):
pass
with self.assertRaisesRegex(TypeError,
r'Cannot subclass typing\.Union\[int, str\]'):
r'Cannot subclass int \| str'):
class E(Union[int, str]):
pass

Expand Down
1 change: 1 addition & 0 deletions Modules/_typingmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "internal/pycore_interp.h"
#include "internal/pycore_typevarobject.h"
#include "internal/pycore_unionobject.h" // _PyUnion_Type
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "clinic/_typingmodule.c.h"

/*[clinic input]
Expand Down
11 changes: 7 additions & 4 deletions Objects/unionobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,14 @@ union_origin(PyObject *Py_UNUSED(self), void *Py_UNUSED(ignored))
}

static PyGetSetDef union_properties[] = {
{"__name__", union_name, NULL, "Name of the type", NULL},
{"__qualname__", union_name, NULL, "Qualified name of the type", NULL},
{"__origin__", union_origin, NULL, "Always returns the type", NULL},
{"__name__", union_name, NULL,
PyDoc_STR("Name of the type"), NULL},
{"__qualname__", union_name, NULL,
PyDoc_STR("Qualified name of the type"), NULL},
{"__origin__", union_origin, NULL,
PyDoc_STR("Always returns the type"), NULL},
{"__parameters__", union_parameters, (setter)NULL,
"Type variables in the types.UnionType.", NULL},
PyDoc_STR("Type variables in the types.UnionType."), NULL},
{0}
};

Expand Down

0 comments on commit 98b634a

Please sign in to comment.