Docformatter produces error when parsing docstring with Ruff noqa at the end
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
Research direction
Reproduce the supplied Python docstring example and trace docformatter/format.py through tokenize.untokenize, focusing on token positions around the trailing Ruff noqa comment. Done means formatting completes without ValueError and preserves the noqa directive.
Written by the indexing model from the issue text.
Description
When a docstring has a noqa directive at the end (used for suppressing one off linting errors in a docstring), docformatter throws an error.
Ex:
File:
"""
conf.py
~~~~~~~
Copyright (C) 2024 Noah Jenner under CC BY-SA 4.0.
To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/
------------------------------------------------------------------------
Configuration file for Sphinx.
""" # noqa: D205, D400
Error output:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\noahj\.local\bin\docformatter.exe\__main__.py", line 10, in <module>
sys.exit(main())
~~~~^^
File "C:\Users\noahj\AppData\Roaming\uv\data\tools\docformatter\Lib\site-packages\docformatter\__main__.py", line 144, in main
return _main(
sys.argv,
...<2 lines>...
standard_in=sys.stdin,
)
File "C:\Users\noahj\AppData\Roaming\uv\data\tools\docformatter\Lib\site-packages\docformatter\__main__.py", line 134, in _main
return formator.do_format_files()
~~~~~~~~~~~~~~~~~~~~~~~~^^
File "C:\Users\noahj\AppData\Roaming\uv\data\tools\docformatter\Lib\site-packages\docformatter\format.py", line 649, in do_format_files
result = self._do_format_file(filename)
File "C:\Users\noahj\AppData\Roaming\uv\data\tools\docformatter\Lib\site-packages\docformatter\format.py", line 815, in _do_format_file
formatted_source = self._do_format_code(source)
File "C:\Users\noahj\AppData\Roaming\uv\data\tools\docformatter\Lib\site-packages\docformatter\format.py", line 876, in _do_format_code
_code = tokenize.untokenize(self.new_tokens)
File "C:\Users\noahj\AppData\Roaming\uv\data\python\cpython-3.14.2-windows-x86_64-none\Lib\tokenize.py", line 341, in untokenize
out = ut.untokenize(iterable)
File "C:\Users\noahj\AppData\Roaming\uv\data\python\cpython-3.14.2-windows-x86_64-none\Lib\tokenize.py", line 262, in untokenize
self.add_whitespace(start)
~~~~~~~~~~~~~~~~~~~^^^^^^^
File "C:\Users\noahj\AppData\Roaming\uv\data\python\cpython-3.14.2-windows-x86_64-none\Lib\tokenize.py", line 178, in add_whitespace
raise ValueError("start ({},{}) precedes previous end ({},{})"
.format(row, col, self.prev_row, self.prev_col))
ValueError: start (11,5) precedes previous end (12,0)
This occurs regardless of options passed into the command line.
Removing the directives does fix the problem, though this reintroduces linting errors produced by Ruff or other linters.
- Dominant language
- Python
- Stars
- 600
- Forks
- 107
- Avg merge
- 22h 15m
- Merged PRs (30d)
- 12
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
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.
More from PyCQA/docformatter
-
`--docstring-length` removes blank line after docstrings it doesn't format (ping-pong with ruff format / Black)Possibly taken @RClaudiuM claimed this 1 day ago. Openfresh
Difficulty 3/5 1-2 days Newbie friendliness 68/100
PyCQA/docformatter#420 ·
Maintainers usually reply within 1 day
-
fresh
Difficulty 3/5 1-2 days Newbie friendliness 66/100
PyCQA/docformatter#414 · 1 reaction ·
Maintainers usually reply within 1 day
-
docformatter fix does not consider parameters for added newlinesMay be free again @AtharvRG claimed this 25 days ago, and no pull request is open. Openfresh
Difficulty 3/5 1-2 days Newbie friendliness 68/100
PyCQA/docformatter#408 · 1 comment ·
Maintainers usually reply within 1 day
-
BUG: Inconsistent behavior between `docformatter` and `black`May be free again @AtharvRG claimed this 25 days ago, and no pull request is open. Openfresh
Difficulty 3/5 1-2 days Newbie friendliness 58/100
PyCQA/docformatter#399 · 1 comment ·
Maintainers usually reply within 1 day
-
1.7.8 crashes with a tokenize ValueError on a multi-line f-string inside parenthesesMay be free again @adityaanikam claimed this 106 days ago, and no pull request is open. OpenC: convention P: bug U: high
Difficulty 3/5 1-2 days Newbie friendliness 74/100
PyCQA/docformatter#367 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
All issues in PyCQA/docformatter
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
NatLabRockies/openstudio-mcp#286 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
intersystems/ipm#1338 ·
Maintainers usually reply within 1 day
-
separate_packages splits imports from the same explicitly configured packagePossibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
The v0-through-v1 path derives ShutdownDuration its own way, silently overriding a user's definitionOpenv1
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day