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

Need a way to avoid adding docstring for __init__ #15

Open
aannara opened this issue Oct 9, 2023 · 3 comments
Open

Need a way to avoid adding docstring for __init__ #15

aannara opened this issue Oct 9, 2023 · 3 comments

Comments

@aannara
Copy link

aannara commented Oct 9, 2023

Currently if __init__ does not have a docstring. We get this error: DCO010 docstring should be defined for a function/ method/ class, more information: https://github.com/jdkandersson/flake8-docstrings-complete#fix-dco010.

Need an ability to avoid adding docstring for __init__.

If this linter is able to detect __init__ and other dunder/magic methods, then it can be added as a new DOC rule and it can be ignored either by flake8 or by the tool itself.

@jdkandersson
Copy link
Owner

This would be a breaking change due to previous disables people have used not working anymore for magic methods. Before releasing that it would probably be worthwhile to consider the other rule codes. These should be straight forward to implement based on the linked PR. The ones I would consider are:

  • DCO020 (making it DCO026)
  • DCO023 (making it DCO027)
  • DCO030 (making it DCO033)
  • DCO040 (making it DCO043)
  • DCO050 (making it DCO057)
  • DCO053 (making it DCO058)

I would also create a shared function which determines whether a method is a magic method somewhere

@vpoulailleau
Copy link

@jdkandersson To my mind, __init__ is a special magic method, considering that several projects merge the class docstring and the __init__ docstring into the class docstring (leading to __init__ having no docstring at all).

For instance, Google styleguide states:

The __init__ method may be documented in either the class level docstring, or as a docstring on the __init__ method itself. Either form is acceptable, but the two should not be mixed. Choose one convention to document the __init__ method and be consistent with it.

So, I think there are 3 cases:

  • standard methods
  • __init__
  • other magic methods

What do you think about the paragraph in Google styleguide?

@jdkandersson
Copy link
Owner

I think it is a fair request to have a specific rule to target __init__. Personally, I think it is worthwhile to document arguments to __init__ since they are arguments to the constructor. In version 2 of flake8-docstrings-complete it will be possible to disable a specific rule which will remove the requirement for a docstring on __init__, see #23. I also looked at a few other rules and I think it makes sense to treat them differently for magic methods too. I just haven't gotten around to implementing that yet, though #23 should be relatively easy to follow to implement the rest of the rules noted above. PRs welcome 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants