Docformatter inappropriately removes newline between classes
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 66/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- developer-experience, tooling
Research direction
Start by reproducing the report with the minimal Annotated class examples and docformatter 1.7.8, then trace the formatter’s handling of attribute docstrings and blank lines between classes. Compare the examples with and without a following method to narrow down the case. Done when formatting preserves the blank line between classes consistently with Black and the reported pre-commit deadlock is resolved.
Written by the indexing model from the issue text.
Description
I am currently experiencing a pre-commit deadlock between Black and Docformatter , but only in a very specific case.
Consider the following:
from typing import Annotated, Any
class VisibleWhen:
"""Describe the condition that controls a parameter's visibility."""
equals: Annotated[Any, dict(something=1)]
"""Value that makes the parameter visible."""
class TransformParameter:
"""Define an input parameter accepted by a transform."""
Docformatter is removing a newline from in between the docstring for the equals property and the TransformParameter class, causing a deadlock in pre-commit because black puts two blank lines between classes.
This appears to only affect classes that use Annotated, and only if one of the parameters to Annotated contains a callable at any point with a keyword argument. The property must also not be followed by any methods. For example, this has the same bug:
from typing import Annotated, Any
class VisibleWhen:
"""Describe the condition that controls a parameter's visibility."""
equals: Annotated[Any, {"something": dict(something=1)}]
"""Value that makes the parameter visible."""
class TransformParameter:
"""Define an input parameter accepted by a transform."""
But this does not:
from typing import Annotated, Any
class VisibleWhen:
"""Describe the condition that controls a parameter's visibility."""
equals: Annotated[Any, {"something": dict(something=1)}]
"""Value that makes the parameter visible."""
def function(self):
"""Does a thing."""
class TransformParameter:
"""Define an input parameter accepted by a transform."""
I also found that in this scenario, it removes the newline between the classes:
from typing import Annotated, Any
class VisibleWhen:
"""Describe the condition that controls a parameter's visibility."""
equals: Annotated[Any, {"something": dict(something=1)}]
"""Value that makes the parameter visible."""
prop: Any
"""A description of the property."""
class TransformParameter:
"""Define an input parameter accepted by a transform."""
Versions and Config
I am using docformatter version 1.7.8. Below are my settings for both Black and Docformatter:
[tool.docformatter]
recursive = true
blank = true
black = true
in-place = true
[tool.black]
unstable = true
enable-unstable-feature = ["string_processing"]
- 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
-
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
-
1.7.8 rewrites the contents of a non-docstring triple-quoted string, silently changing its valueOpenC: convention P: bug U: high
Difficulty 3/5 1-2 days Newbie friendliness 72/100
PyCQA/docformatter#366 · 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