Merge pull request #8805 from tk0miya/8775_workaround

Fix #8775: Avoid the crash of autodoc caused by type union operator
This commit is contained in:
Takeshi KOMIYA 2021-02-01 21:35:04 +09:00 committed by GitHub
commit f803266d63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -77,7 +77,9 @@ def get_type_hints(obj: Any, globalns: Dict = None, localns: Dict = None) -> Dic
# Failed to evaluate ForwardRef (maybe TYPE_CHECKING)
return safe_getattr(obj, '__annotations__', {})
except TypeError:
return {}
# Invalid object is given. But try to get __annotations__ as a fallback for
# the code using type union operator (PEP 604) in python 3.9 or below.
return safe_getattr(obj, '__annotations__', {})
except KeyError:
# a broken class found (refs: https://github.com/sphinx-doc/sphinx/issues/8084)
return {}

View File

@ -2237,7 +2237,7 @@ def test_name_mangling(app):
]
@pytest.mark.skipif(sys.version_info < (3, 10), reason='python 3.10+ is required.')
@pytest.mark.skipif(sys.version_info < (3, 7), reason='python 3.7+ is required.')
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_type_union_operator(app):
options = {'members': None}