gh-105499: Merge typing.Union and types.UnionType (#105511)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: Carl Meyer <carl@oddbird.net>
This commit is contained in:
Jelle Zijlstra 2025-03-04 11:44:19 -08:00 committed by GitHub
parent e091520fdb
commit dc6d66f44c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 562 additions and 327 deletions

View file

@ -133,7 +133,7 @@ DATA
c_alias = test.test_pydoc.pydoc_mod.C[int]
list_alias1 = typing.List[int]
list_alias2 = list[int]
type_union1 = typing.Union[int, str]
type_union1 = int | str
type_union2 = int | str
VERSION
@ -223,7 +223,7 @@ Data
c_alias = test.test_pydoc.pydoc_mod.C[int]
list_alias1 = typing.List[int]
list_alias2 = list[int]
type_union1 = typing.Union[int, str]
type_union1 = int | str
type_union2 = int | str
Author
@ -1447,17 +1447,17 @@ class TestDescriptions(unittest.TestCase):
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
def test_union_type(self):
self.assertEqual(pydoc.describe(typing.Union[int, str]), '_UnionGenericAlias')
self.assertEqual(pydoc.describe(typing.Union[int, str]), 'Union')
doc = pydoc.render_doc(typing.Union[int, str], renderer=pydoc.plaintext)
self.assertIn('_UnionGenericAlias in module typing', doc)
self.assertIn('Union = typing.Union', doc)
self.assertIn('Union in module typing', doc)
self.assertIn('class Union(builtins.object)', doc)
if typing.Union.__doc__:
self.assertIn(typing.Union.__doc__.strip().splitlines()[0], doc)
self.assertEqual(pydoc.describe(int | str), 'UnionType')
self.assertEqual(pydoc.describe(int | str), 'Union')
doc = pydoc.render_doc(int | str, renderer=pydoc.plaintext)
self.assertIn('UnionType in module types object', doc)
self.assertIn('\nclass UnionType(builtins.object)', doc)
self.assertIn('Union in module typing', doc)
self.assertIn('class Union(builtins.object)', doc)
if not MISSING_C_DOCSTRINGS:
self.assertIn(types.UnionType.__doc__.strip().splitlines()[0], doc)