mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
commit
f803266d63
@ -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 {}
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user