Docformatter inappropriately removes newline between classes

Aperta
#414 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
66/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

fresh

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"]
Lingua principale
Python
Stelle
600
Fork
107
Merge medio
22h 15m
PR unite (30g)
12

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PyCQA/docformatter

Tutte le issue di PyCQA/docformatter

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.