From 8911c2254fab61ab7f18dd5694862041e9512d47 Mon Sep 17 00:00:00 2001 From: Han Guangyu Date: Thu, 28 Mar 2024 11:19:17 +0800 Subject: [PATCH] Fix sphinx-build crashed with Python 3.10+ `types.Union` was renamed to `types.UnionType` since Python 3.10 (refs: python/cpython#27342). After this change, sphinx-build has been crashed because of ImportError. Origin: https://github.com/sphinx-doc/sphinx/commit/8b2031c747e7c7e6b845ee2e3db47de617d33cc6 --- ...-build-crashed-with-Python-3.10-plus.patch | 56 +++++++++++++++++++ python-sphinx.spec | 6 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 0002-Fix-sphinx-build-crashed-with-Python-3.10-plus.patch diff --git a/0002-Fix-sphinx-build-crashed-with-Python-3.10-plus.patch b/0002-Fix-sphinx-build-crashed-with-Python-3.10-plus.patch new file mode 100644 index 0000000..b84a660 --- /dev/null +++ b/0002-Fix-sphinx-build-crashed-with-Python-3.10-plus.patch @@ -0,0 +1,56 @@ +From 637cb27d285fe73c359ddf00d27400878fa6832f Mon Sep 17 00:00:00 2001 +From: Han Guangyu +Date: Thu, 28 Mar 2024 10:52:43 +0800 +Subject: [PATCH 1/1] Fix sphinx-build crashed with Python 3.10+ + +`types.Union` was renamed to `types.UnionType` since Python 3.10 + (refs: python/cpython#27342). After this change, sphinx-build has been + crashed because of ImportError. + +Origin: +https://github.com/sphinx-doc/sphinx/commit/8b2031c747e7c7e6b845ee2e3db47de617d33cc6 + +--- + sphinx/util/typing.py | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py +index db754bb..cc06a3b 100644 +--- a/sphinx/util/typing.py ++++ b/sphinx/util/typing.py +@@ -30,10 +30,10 @@ else: + 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 +@@ -107,7 +107,7 @@ def restify(cls: Optional["Type"]) -> str: + return ':class:`struct.Struct`' + 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 +@@ -349,7 +349,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 +-- +2.43.0 + diff --git a/python-sphinx.spec b/python-sphinx.spec index e91fcad..cc3707a 100644 --- a/python-sphinx.spec +++ b/python-sphinx.spec @@ -1,12 +1,13 @@ Name: python-sphinx Version: 3.5.2 -Release: 1 +Release: 2 Epoch: 1 Summary: Python documentation generator License: BSD and MIT URL: http://sphinx-doc.org/ Source0: https://files.pythonhosted.org/packages/source/S/Sphinx/Sphinx-%{version}.tar.gz Patch1: sphinx-test_theming.diff +Patch2: 0002-Fix-sphinx-build-crashed-with-Python-3.10-plus.patch BuildArch: noarch @@ -225,6 +226,9 @@ export PATH=%{buildroot}%{_bindir}:$PATH %{_mandir}/man1/* %changelog +* Thu Mar 28 2024 Han Guangyu - 1:3.5.2-2 +- Fix sphinx-build crashed with Python 3.10+ + * Tue Jul 27 2021 OpenStack_SIG - 3.5.2-1 - update to 3.5.2 -- Gitee