Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single quoted word in argument breaks docstring parsing #7

Open
jamesbraza opened this issue Jun 23, 2024 · 3 comments
Open

Single quoted word in argument breaks docstring parsing #7

jamesbraza opened this issue Jun 23, 2024 · 3 comments

Comments

@jamesbraza
Copy link

The below code with Python 3.12 and python-cdd==0.0.99rc47:

import cdd.docstring.parse

def my_function(arg: str) -> None:
    """Summary.

    Args:
        arg: A 'quoted' word. 
    """

cdd.docstring.parse.docstring(my_function.__doc__)

Will crash _parse_adhoc_doc_for_typ_phase0 with TypeError: unhashable type: 'list'

Traceback (most recent call last):
...
  File "/path/to/venv/lib/python3.12/site-packages/cdd/docstring/utils/parse_utils.py", line 263, in parse_adhoc_doc_for_typ
    candidate_type, fst_sentence, sentence = _parse_adhoc_doc_for_typ_phase0(doc, words)
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/venv/lib/python3.12/site-packages/cdd/docstring/utils/parse_utils.py", line 410, in _parse_adhoc_doc_for_typ_phase0
    candidate_type: Optional[str] = next(
                                    ^^^^^
TypeError: unhashable type: 'list'
@jamesbraza jamesbraza changed the title Single quotes in argument breaks parsing Single quoted word in argument breaks docstring parsing Jun 23, 2024
@SamuelMarks
Copy link
Member

Good to have the bug report, checking the words are:

['A', ' ', [], '', '', ['q', 'u', 'o', 't', 'e', 'd'], 'quoted', '', ' ', 'word', '.']

Which is certainly not what is wanted at this stage.

In the middle of something let me see if I can resolve this issue in the next week. Thanks for using the library!

@jamesbraza
Copy link
Author

Yeah sounds good and thank you! I am trying to use this to go from type hinted signatures + docstrings to an OpenAPI spec

@SamuelMarks
Copy link
Member

Good plan. The project is just about ready to do that reliably.

Anyway, will address the issue you brought up. Also have an uncommitted local build with some other improvements relating to type inference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants