theislab / scanpydoc

Collection of Sphinx extensions similar to (but more flexible than) numpydoc
https://icb-scanpydoc.readthedocs-hosted.com/en/latest/
GNU General Public License v3.0
12 stars 6 forks source link

Use of typing.Dict throws an error in elegant_typehints #38

Closed ipsingh06 closed 3 years ago

ipsingh06 commented 3 years ago

Using an annotation of typing.Dict throws an error during Sphinx build. typing.Dict[Any, Any] is fine.

Traceback (most recent call last):                                                                                                              
  File "/workspace/.venv/lib/python3.8/site-packages/sphinx/events.py", line 101, in emit                                    
    results.append(listener.handler(self.app, *args))                                                                                           
  File "/workspace/.venv/lib/python3.8/site-packages/sphinx_autodoc_typehints.py", line 425, in process_docstring            
    formatted_annotation = format_annotation(                                                                                                   
  File "/workspace/.venv/lib/python3.8/site-packages/scanpydoc/elegant_typehints/formatting.py", line 123, in format_annotati
on                                                                                                                                                  annot_fmt = format_both(annotation, fully_qualified, simplify_optional_unions)                                                              
  File "/workspace/.venv/lib/python3.8/site-packages/scanpydoc/elegant_typehints/formatting.py", line 142, in format_both    
    terse = _format_terse(annotation, fully_qualified, simplify_optional_unions)                                                                
  File "/workspace/.venv/lib/python3.8/site-packages/scanpydoc/elegant_typehints/formatting.py", line 78, in _format_terse       return f"{{{fmt(k)}: {fmt(v)}}}"                                                                                                            
  File "/workspace/.venv/lib/python3.8/site-packages/scanpydoc/elegant_typehints/formatting.py", line 77, in _format_terse   
    k, v = get_args(annotation)                                                                                                                 
ValueError: not enough values to unpack (expected 2, got 0)                                                                                     
flying-sheep commented 3 years ago

Is it valid to use it like that? Shouldn’t you use typing.Dict[Any, Any] or dict anyway?

ipsingh06 commented 3 years ago

I've found it to generally work with type checkers, though I agree the two other methods you mentioned should be preferred. I think this case should still be handled more gracefully because currently the build will fail with no helpful indicator as to where the issue is. What do you think?