From 924f1b1e382cf79763e2e2b741e88b6822da4f42 Mon Sep 17 00:00:00 2001 From: Karolina Surma Date: Tue, 3 Aug 2021 18:00:12 +0200 Subject: [PATCH] Backport a patch to make python-sphinx work with Python 3.10-rc1 types.Union was renamed to types.UnionType, causing Sphinx to crash --- python-sphinx.spec | 4 ++ rename-types-Union-to-types-UnionType.patch | 49 +++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 rename-types-Union-to-types-UnionType.patch diff --git a/python-sphinx.spec b/python-sphinx.spec index 7c77cd7..6b4300d 100644 --- a/python-sphinx.spec +++ b/python-sphinx.spec @@ -44,6 +44,9 @@ Source0: %{pypi_source %{upstream_name} %{upstream_version}} # Allow extra themes to exist. We pull in python3-sphinx-theme-alabaster # which causes that test to fail. Patch1: sphinx-test_theming.diff +# `types.Union` was renamed to `types.UnionType` on the HEAD of Python 3.10 +# (refs: python/cpython#27342). Afterwars, sphinx-build crashes because of ImportError +Patch2: rename-types-Union-to-types-UnionType.patch BuildArch: noarch @@ -368,6 +371,7 @@ mkdir %{buildroot}%{python3_sitelib}/sphinxcontrib * Mon Aug 02 2021 Karolina Surma - 1:4.1.2-1 - Update to 4.1.2 - Fixes rhbz#1979326 +- Backport commit to fix python-sphinx with Python 3.10-rc1 * Fri Jul 23 2021 Fedora Release Engineering - 1:4.0.2-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild diff --git a/rename-types-Union-to-types-UnionType.patch b/rename-types-Union-to-types-UnionType.patch new file mode 100644 index 0000000..a6b8c35 --- /dev/null +++ b/rename-types-Union-to-types-UnionType.patch @@ -0,0 +1,49 @@ +From 8b2031c747e7c7e6b845ee2e3db47de617d33cc6 Mon Sep 17 00:00:00 2001 +From: Takeshi KOMIYA +Date: Fri, 30 Jul 2021 01:27:38 +0900 +Subject: [PATCH] Fix #9512: sphinx-build: crashed with the HEAD of Python 3.10 + +Recently, `types.Union` was renamed to `types.UnionType` on the HEAD +of 3.10 (refs: python/cpython#27342). After this change, sphinx-build +has been crashed because of ImportError. +--- + sphinx/util/typing.py | 12 ++++++------ + 1 files changed, 8 insertions(+), 6 deletions(-) + +diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py +index f1723c035a..012d32e524 100644 +--- a/sphinx/util/typing.py ++++ b/sphinx/util/typing.py +@@ -33,10 +33,10 @@ def _evaluate(self, globalns: Dict, localns: Dict) -> Any: + ref = _ForwardRef(self.arg) + return ref._eval_type(globalns, localns) + +-if sys.version_info > (3, 10): +- from types import Union as types_Union +-else: +- types_Union = None ++try: ++ from types import UnionType # type: ignore # python 3.10 or above ++except ImportError: ++ UnionType = None + + if False: + # For type annotation +@@ -114,7 +114,7 @@ def restify(cls: Optional[Type]) -> str: + return ':class:`%s`' % INVALID_BUILTIN_CLASSES[cls] + elif inspect.isNewType(cls): + return ':class:`%s`' % cls.__name__ +- elif types_Union and isinstance(cls, types_Union): ++ elif UnionType and isinstance(cls, UnionType): + if len(cls.__args__) > 1 and None in cls.__args__: + args = ' | '.join(restify(a) for a in cls.__args__ if a) + return 'Optional[%s]' % args +@@ -337,7 +337,7 @@ def _stringify_py37(annotation: Any) -> str: + elif hasattr(annotation, '__origin__'): + # instantiated generic provided by a user + qualname = stringify(annotation.__origin__) +- elif types_Union and isinstance(annotation, types_Union): # types.Union (for py3.10+) ++ elif UnionType and isinstance(annotation, UnionType): # types.Union (for py3.10+) + qualname = 'types.Union' + else: + # we weren't able to extract the base type, appending arguments would