Description of the bug
I ran typesplainer
on my code base and it crashed on the type Optional[Awaitable]
. Using mypy
on the same file produced no diagnostics indicating a problem with the typing. I've included a reproducer class and the stack trace in the additional information section.
Steps To Reproduce
- installed from pypi
- ran on reproducer:
python3 -m typesplainer reproducer.py
- crash
Additional Information
# reproducer.py
from typing import Awaitable, Optional
class BugClass:
def no_crash(self) -> Optional[Awaitable[None]]:
"""A method that returns None or an Awaitable"""
def crashes(self) -> Optional[Awaitable]:
"""A method that returns None or an Awaitable"""
$ python3 -m typesplainer reproducer.py
Optional[Awaitable[None]] (reproducer.py:5:27) : A optional awaitable that returns nothing/none.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/__main__.py", line 99, in <module>
print_description(f.read(), file_name=file)
File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/__main__.py", line 45, in print_description
console.print(text, format_location(def_, typehint_text, file_name), ":", describe(def_))
File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/core.py", line 200, in describe
return _describe(thing).capitalize() + "."
File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/core.py", line 47, in _describe
return f"{'a ' if a else ''}optional {_describe(thing.args[0], a=False, plural=plural)}"
File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/core.py", line 132, in _describe
return f"{'a ' if a else ''}awaitable that returns {_describe(thing.args[0])}"
IndexError: tuple index out of range
[VE] ejo@ufo:bl2 ->
bug