Skip to content

Single quotes in triple-quoted docstring raise AssertionError #489

@jacobtylerwalls

Description

@jacobtylerwalls

👋 !

Some chatter in the Django forum today about whether to lint docstrings, so I gave this project a test drive on Django, and noticed an error on a source like this:

def a(self):
    "'a.m.' or 'p.m.'"
    if self.data.hour > 11:
        return _("p.m.")
    return _("a.m.")
pydocstringformatter a.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/bin/pydocstringformatter", line 8, in <module>
    sys.exit(run_docstring_formatter())
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydocstringformatter/__init__.py", line 18, in run_docstring_formatter
    _Run(argv or sys.argv[1:])
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 34, in __init__
    self.check_files(self.config.files)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 41, in check_files
    is_changed = self.format_files(filepaths)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 202, in format_files
    is_changed = [self.format_file(file) for file in filepaths]
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 68, in format_file
    formatted_tokens, is_changed = self.format_file_tokens(tokens, filename)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 139, in format_file_tokens
    new_tokeninfo, changers = self.apply_formatters(new_tokeninfo)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 175, in apply_formatters
    token, changers = self._apply_formatters_once(token)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydocstringformatter/run.py", line 194, in _apply_formatters_once
    if (new_token := formatter.treat_token(token)) != token:
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydocstringformatter/_formatting/base.py", line 96, in treat_token
    assert quotes_length in {1, 3}
AssertionError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions