typing.py classes with Python 3.7
Subject: Sphinx fails in Python 3.7 for classes in typing.py
Problem
- From Python3.7 onwards, some classes of typing.py are no longer true "classes" but objects of other classes. For example, Tuple is now an object of _VariadicGenericAlias.
Therefore, Python 3.7 onwards, the "name" attribute doesn't exist for such classes any more.
This is while building the docs for https://github.com/facebookresearch/pytext.
https://github.com/facebookresearch/pytext/blob/f55c96c1ba9085a0148bca8d854975b96c277a9b/pytext/data/featurizer/simple_featurizer.py#L18 this is where Sphinx fails.
This can be used for reproduction of the error.
Procedure to reproduce the problem
make html
Error logs / results
# Sphinx version: 1.8.3
# Python version: 3.7.1 (CPython)
# Docutils version: 0.14
# Jinja2 version: 2.10
# Last messages:
# Loaded extensions:
Traceback (most recent call last):
File "/Users/snisarg/code/OpenSource/pytext/pytext_venv/lib/python3.7/site-packages/sphinx/cmd/build.py", line 303, in build_main
args.tags, args.verbosity, args.jobs, args.keep_going)
File "/Users/snisarg/code/OpenSource/pytext/pytext_venv/lib/python3.7/site-packages/sphinx/application.py", line 263, in __init__
self._init_builder()
File "/Users/snisarg/code/OpenSource/pytext/pytext_venv/lib/python3.7/site-packages/sphinx/application.py", line 325, in _init_builder
self.emit('builder-inited')
File "/Users/snisarg/code/OpenSource/pytext/pytext_venv/lib/python3.7/site-packages/sphinx/application.py", line 510, in emit
return self.events.emit(event, self, *args)
File "/Users/snisarg/code/OpenSource/pytext/pytext_venv/lib/python3.7/site-packages/sphinx/events.py", line 80, in emit
results.append(callback(*args))
File "/Users/snisarg/code/OpenSource/pytext/pytext/docs/source/conf.py", line 191, in run_apidoc
main()
File "/Users/snisarg/code/OpenSource/pytext/pytext/docs/make_config_docs.py", line 321, in main
config_rst.write(format_config_rst(config))
File "/Users/snisarg/code/OpenSource/pytext/pytext/docs/make_config_docs.py", line 222, in format_config_rst
for attr in attrs
File "/Users/snisarg/code/OpenSource/pytext/pytext/docs/make_config_docs.py", line 222, in <genexpr>
for attr in attrs
File "/Users/snisarg/code/OpenSource/pytext/pytext/docs/make_config_docs.py", line 83, in marked_up_type_name
return f"Optional[{marked_up_type_name(optional_type)}]"
File "/Users/snisarg/code/OpenSource/pytext/pytext/docs/make_config_docs.py", line 88, in marked_up_type_name
return f"{arg_type.__name__}[{', '.join(options)}]"
File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/typing.py", line 699, in __getattr__
raise AttributeError(attr)
AttributeError: __name__
Expected results
Sphinx should pass and build docs.
Reproducible project / your project
- https://github.com/facebookresearch/pytext
Environment info
- OS: Mac
- Python version: 3.7.1
- Sphinx version: 1.8.3
It seems the error came from pytext/docs/make_config_docs.py. What is the script doing?
Actually I think I mixed up 2 separate issues. Lemme sort this out and create a new one if it's still there.