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

Incorrect handling of cvar, ivar and vartype tags in sphynx-style #271

Open
pedropaulofb opened this issue Nov 23, 2023 · 6 comments
Open
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: bug PEP 257 violation or existing functionality that doesn't work as documented U: medium A relatively medium urgency issue

Comments

@pedropaulofb
Copy link

I would like to use cvar, ivar and vartype of the sphyx docstring syntax, however, docformatter is incorrectly handling them.

Expected:

    """Abstract base class representing a generic element within an OntoUML model.

    :ivar id: A unique identifier for the element, automatically generated upon instantiation.
    :vartype id: str
    :ivar created: Timestamp when the element was created, defaults to the current time.
    :vartype created: datetime
    :ivar modified: Timestamp when the element was last modified, can be None if not modified.
    :vartype modified: Optional[datetime]
    :ivar in_project: List of projects this element is part of. Direct modification is restricted.
    :vartype in_project: list[Project]
    """

Result:

    """Abstract base class representing a generic element within an OntoUML model.

    :ivar id: A unique identifier for the element, automatically generated upon instantiation. :vartype id: str :ivar
    created: Timestamp when the element was created, defaults to the current time. :vartype created: datetime :ivar
    modified: Timestamp when the element was last modified, can be None if not modified. :vartype modified:
    Optional[datetime] :ivar in_project: List of projects this element is part of. Direct modification is restricted.
    :vartype in_project: list[Project]
    """

Is there a workaround to solve this issue?

@github-actions github-actions bot added the fresh This is a new issue label Nov 23, 2023
@electric-coder
Copy link

@pedropaulofb notice the warning in the Sphinx docs about the info field lists, for reference:

Note

In current release, all var, ivar and cvar are represented as “Variable”. There is no difference at all.

docformatter should be formatting the fields correctly.

@pedropaulofb
Copy link
Author

@electric-coder, thank you for your answer and interest in helping me. As you can see in the examples I sent, at least to me this is not happening. Am I missing any config or is there something else I can try?

@electric-coder
Copy link

electric-coder commented Dec 2, 2023

@pedropaulofb I'm using docformatter version 1.7.2 (check your version with docformatter --version).

I'm also using standard configurations to wrap in accordance with the python-black code style, so in my pyproject.toml I have:

[tool.docformatter]
black = true
wrap-descriptions = 88
wrap-summaries = 88

For me docformatter is wrapping the lines correctly, after I run it on your example I get:

def my_method(a, b):
    """Abstract base class representing a generic element within an OntoUML model.

    :ivar id: A unique identifier for the element, automatically generated upon
        instantiation.
    :vartype id: str
    :ivar created: Timestamp when the element was created, defaults to the current time.
    :vartype created: datetime
    :ivar modified: Timestamp when the element was last modified, can be None if not
        modified.
    :vartype modified: Optional[datetime]
    :ivar in_project: List of projects this element is part of. Direct modification is
        restricted.
    :vartype in_project: list[Project]
    """
    some_text = 1

So this result is correct. I think there was a bug in a previous docformatter version that's been resolved and might cause the problems you are describing, try updating to a more recent version or setting the .toml configs... Your example docstring also wasn't inserted in a class or function, so you should put it inside a correct pythonic scope.

@pedropaulofb
Copy link
Author

pedropaulofb commented Dec 3, 2023

Dear @electric-coder , thank you for your help! I have the following pyproject.toml configuration:

[tool.docformatter]
black = true
wrap-descriptions = 120
wrap-summaries = 120

My tests were performed in this file.

Indeed, when I used version 1.7.2, I got the expected results. When using version 1.7.5 the results were the ones I reported (i.e., the wrong ones). So I also tested versions 1.7.3 (got correct results) and 1.7.4 (got wrong results). Hence, we can conclude that it is a bug introduced in versions >= 1.7.4.

Could you please reproduce the test yourself?

@electric-coder
Copy link

@pedropaulofb I'm not a docformatter maintainer, just a user. I'm sure your tests are correct so I'll excuse myself from the extra work of installing an additional venv to reproduce them.

I think this issue is likely the same as #264

@pedropaulofb
Copy link
Author

@electric-coder , It was not a problem! Thank you very much!

@weibullguy weibullguy added P: bug PEP 257 violation or existing functionality that doesn't work as documented C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) and removed fresh This is a new issue labels Dec 21, 2023
@github-actions github-actions bot added the U: medium A relatively medium urgency issue label Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: style Relates to docstring format style (e.g., Google, NumPy, Sphinx) P: bug PEP 257 violation or existing functionality that doesn't work as documented U: medium A relatively medium urgency issue
Projects
None yet
Development

No branches or pull requests

3 participants