readthedocs / readthedocs/sphinx-autoapi
`Cannot resolve import` on re-imported class from module.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 494
- Forks
- 147
- Avg merge
- 9m
- Merged PRs (30d)
- 1
Description
In airflow we like to run with -W flag (to turn warnings in to errors) and we are "stuck" on 1.0.0 for various reasons. (One day soon we'll be able to upgrade!)
This was actually an error/warning that first appeared in 1.1.0, but is still there in 1.8.0
What the export is doesn't matter, this was just what triggered it first in Airflow.
Setup:
mkdir -p airflow/
touch airflow/__init__.py
cat > airflow/typing_compat.py <<EOF
try:
from typing import Protocol, TypedDict, runtime_checkable # type: ignore # noqa
except ImportError:
from typing_extensions import Protocol, TypedDict, runtime_checkable # type: ignore # noqa
EOF
cat > airflow/stats.py <<EOF
from airflow.typing_compat import Protocol
class TimerProtocol(Protocol):
"""Type protocol for StatsLogger.timer"""
def __enter__(self):
...
def __exit__(self, exc_type, exc_value, traceback):
...
def start(self):
"""Start the timer"""
...
def stop(self, send=True):
"""Stop, and (by default) submit the timer to statsd"""
...
EOF
Run it:
sphinx-build -W --color -T -b html \
-C \
-D autoapi_keep_files=True \
-D extensions=autoapi.extension \
-D autoapi_dirs=airflow \
. _build
Output:
airflow ❯ sphinx-build -W --color -T -b html -C -D autoapi_keep_files=True -D extensions=autoapi.extension -D autoapi_dirs=airflow . _build
Running Sphinx v3.5.4
making output directory... done
[AutoAPI] Loading Data
[AutoAPI] Reading files... [100%] /home/ash/code/python/flask-sqlalchemy/tmp/airflow/typing_compat.py
[AutoAPI] Mapping Data
Traceback (most recent call last):
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/sphinx/cmd/build.py", line 279, in build_main
args.tags, args.verbosity, args.jobs, args.keep_going)
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/sphinx/application.py", line 278, in __init__
self._init_builder()
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/sphinx/application.py", line 337, in _init_builder
self.events.emit('builder-inited')
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/sphinx/events.py", line 111, in emit
results.append(listener.handler(self.app, *args))
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/autoapi/extension.py", line 101, in run_autoapi
sphinx_mapper_obj.map(options=app.config.autoapi_options)
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/autoapi/mappers/python/mapper.py", line 243, in map
self._resolve_placeholders()
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/autoapi/mappers/python/mapper.py", line 240, in _resolve_placeholders
_resolve_module_placeholders(modules, module_name, visit_path, resolved)
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/autoapi/mappers/python/mapper.py", line 142, in _resolve_module_placeholders
LOGGER.warning(msg)
File "/usr/lib64/python3.7/logging/__init__.py", line 1734, in warning
self.log(WARNING, msg, *args, **kwargs)
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/sphinx/util/logging.py", line 126, in log
super().log(level, msg, *args, **kwargs)
File "/usr/lib64/python3.7/logging/__init__.py", line 1766, in log
self.logger.log(level, msg, *args, **kwargs)
File "/usr/lib64/python3.7/logging/__init__.py", line 1444, in log
self._log(level, msg, args, **kwargs)
File "/usr/lib64/python3.7/logging/__init__.py", line 1514, in _log
self.handle(record)
File "/usr/lib64/python3.7/logging/__init__.py", line 1524, in handle
self.callHandlers(record)
File "/usr/lib64/python3.7/logging/__init__.py", line 1586, in callHandlers
hdlr.handle(record)
File "/usr/lib64/python3.7/logging/__init__.py", line 890, in handle
rv = self.filter(record)
File "/usr/lib64/python3.7/logging/__init__.py", line 751, in filter
result = f.filter(record)
File "/home/ash/.virtualenvs/airflow/lib/python3.7/site-packages/sphinx/util/logging.py", line 422, in filter
raise exc
sphinx.errors.SphinxWarning: Cannot resolve import of airflow.typing_compat.Protocol in airflow.stats
Warning, treated as error:
Cannot resolve import of airflow.typing_compat.Protocol in airflow.stats
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with autoapi/mappers/python/mapper.py, especially _resolve_module_placeholders(), where the warning is logged. Reproduce the issue with the minimal airflow package and the provided sphinx-build command, then verify that re-exported imports such as airflow.typing_compat.Protocol resolve without a warning treated as an error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100