From 11e9da64f371370947e98c2f794866a93c381d84 Mon Sep 17 00:00:00 2001 From: Yasuhiro Kimura Date: Wed, 11 Aug 2021 19:04:45 +0900 Subject: [PATCH] textproc/py-sphinx: Add upstream patch to fix runtime error with Python 3.10 While testing lang/python310, I found runtime error such as following happens with textproc/py-sphinx if 3.10 is default version of Python. ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/local/bin/sphinx-build", line 33, in sys.exit(load_entry_point('Sphinx==3.5.2', 'console_scripts', 'sphinx-build')()) File "/usr/local/bin/sphinx-build", line 25, in importlib_load_entry_point return next(matches).load() File "/usr/local/lib/python3.10/importlib/metadata/__init__.py", line 162, in load module = import_module(match.group('module')) File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/usr/local/lib/python3.10/site-packages/sphinx/cmd/build.py", line 25, in from sphinx.application import Sphinx File "/usr/local/lib/python3.10/site-packages/sphinx/application.py", line 32, in from sphinx.config import Config File "/usr/local/lib/python3.10/site-packages/sphinx/config.py", line 23, in from sphinx.util import logging File "/usr/local/lib/python3.10/site-packages/sphinx/util/__init__.py", line 35, in from sphinx.util import smartypants # noqa File "/usr/local/lib/python3.10/site-packages/sphinx/util/smartypants.py", line 33, in from sphinx.util.docutils import __version_info__ as docutils_version File "/usr/local/lib/python3.10/site-packages/sphinx/util/docutils.py", line 31, in from sphinx.util.typing import RoleFunction File "/usr/local/lib/python3.10/site-packages/sphinx/util/typing.py", line 34, in from types import Union as types_Union ImportError: cannot import name 'Union' from 'types' (/usr/local/lib/python3.10/types.py) ---------------------------------------------------------------------- So add upstream patch to fix the problem. References: https://github.com/sphinx-doc/sphinx/issues/9512 https://github.com/sphinx-doc/sphinx/pull/9513 https://github.com/sphinx-doc/sphinx/commit/36e06d67c9e4ef6d3d0881aac76066b5c1982ccd --- textproc/py-sphinx/Makefile | 1 + .../files/patch-sphinx_util_typing.py | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 textproc/py-sphinx/files/patch-sphinx_util_typing.py diff --git a/textproc/py-sphinx/Makefile b/textproc/py-sphinx/Makefile index 18d37bfdab74..ff770294de6a 100644 --- a/textproc/py-sphinx/Makefile +++ b/textproc/py-sphinx/Makefile @@ -2,6 +2,7 @@ PORTNAME= sphinx PORTVERSION= 3.5.2 +PORTREVISION= 1 PORTEPOCH= 1 CATEGORIES= textproc python MASTER_SITES= CHEESESHOP diff --git a/textproc/py-sphinx/files/patch-sphinx_util_typing.py b/textproc/py-sphinx/files/patch-sphinx_util_typing.py new file mode 100644 index 000000000000..2b21fdd41d1a --- /dev/null +++ b/textproc/py-sphinx/files/patch-sphinx_util_typing.py @@ -0,0 +1,58 @@ +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. +--- CHANGES.orig 2021-03-06 11:59:38 UTC ++++ CHANGES +@@ -419,6 +419,8 @@ Bugs fixed + * #6914: figure numbers are unexpectedly assigned to uncaptioned items + * #8320: make "inline" line numbers un-selectable + ++* #9512: sphinx-build: crashed with the HEAD of Python 3.10 ++ + Testing + -------- + + CHANGES | 2 ++ + sphinx/util/typing.py | 12 ++++++------ + 2 files changed, 8 insertions(+), 6 deletions(-) + +--- sphinx/util/typing.py.orig 2021-03-06 11:58:24 UTC ++++ 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.32.0