Comments (6)
Thanks for sharing this example. Very interesting!
I used this example and stepped through the code. Here is what I found:
- The type hint of
c
in the function signature is correctly parsed as this string:"Literal['Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5', 'Option 6', 'Option 7', 'Option 8', 'Option 9']"
- The type hint of
c
in the docstring, however, is parsed as this string:"Literal['Option 1', 'Option 2', 'Option 3', 'Option 4', 'Option 5',"
That's the reason why you are seeing DOC105.
Pydoclint uses numpydoc, the official numpy docstring library, to parse numpy-style docstrings. As far as I know, numpydoc is a rule-based parser (as opposed to an AI-based parser).
When you put 'Option 6', 'Option 7', 'Option 9', ]
in the 2nd line of the docstring, the parser naturally thinks that it is the description of the argument c
rather than a part of the type hint.
I remember you mentioned over here (astral-sh/ruff#458 (comment)) that pydoclint doesn't provide informative error messages.
I think your assessment is correct in all these 3 cases you mentioned. (This one, #37, and #36) All 3 cases share this similarity: the docstring parser gets confused because the docstring doesn't strictly follow the format.
I think it may be infeasible or at least tricky to really provide "on point" error messages in such cases, simply because the intention of the docstring's author is difficult to infer.
from pydoclint.
The more I think about these 3 cases you raised, the more I think we need another linter that specializes in checking just the style of numpy docstrings. It can be named "numpydocstyle" 😂
In pydocslint's README, I actually recommend people use both pydoclint and pydocstyle together:
Lines 27 to 28 in 1a3596f
The underlying reason is the same: pydoclint's scope is to compare docstring against function signatures. The narrower the scope, the better a job it can do.
from pydoclint.
I think you are completely right, ideally we want to use ruff
(or pydocstyle) for auto formatting and pydoclint
for type check.
If those cases cannot be addressed within the scope of pydoclint
then so be it.
Honestly the minute pydocstyle rule D410 is fixed we'll switch from flake8/darglint to ruff/pydoclint.
The two other issues are very minor hindrance, I just wanted to let you know!
I would like to thank you on behalf on my coworkers for the amazing work you made on pydoclint
in so little time.
from pydoclint.
Thank you! I'm glad that my work can be of help to your team.
Btw, you mentioned that pydoclint couldn't ignore certain rules. If you use pydoclint with flake8, you can use # noqa: DOC...
to ignore certain rules inline.
Do you think running flake8 + pydoclint will be very slow for your projects? I'm personally happy with flake8's speed, probably because I don't deal with large monolith code bases.
The "native" pydoclint doesn't support inline ignoring, because I thought piggybacking flake8's inline ignore is fine. If it is really necessary, I can consider adding inline ignoring.
from pydoclint.
Closing this issue. No action needed.
from pydoclint.
(If I closed this issue by accident, please feel free to leave a comment here.)
from pydoclint.
Related Issues (20)
- Request: not throwing DOC501 for `abstractmethod` HOT 2
- Docs request: `pre-commit` config for `flake8` HOT 1
- Parameters not processed correctly for numpy style with incorrect underscoring HOT 1
- Add shortcuts for long typing.Annotated type hints HOT 3
- BUG: Return literal with double quotes incorrectly raises v203 HOT 3
- Request: Add configuration option that allows for type hint in signature _or_ docstring, but not both HOT 2
- **kwargs only arguments throw DOC106 and DOC109 HOT 2
- Failure to detect the `import typing as tt` convention HOT 2
- Failure to detect `noqa` statement HOT 5
- Google style: Allow omitting only the `Returns`/`Yields` if summary starts with `Return(s)/Yield(s)` HOT 16
- Google style: Allow documenting `@property`s as a member HOT 5
- Allow more control over`--skip-checking-short-docstrings` HOT 4
- More config control for type hinting in signature HOT 2
- Option to only check for non-existent params in pydocs, rather than params missing in pydocs HOT 2
- Deprecated command line argument `--src` leads to errors or missing proper documentation HOT 2
- Google style: Allow omitting `*args` and `**kwargs` from doc string HOT 3
- Add class attributes checking support HOT 1
- False positive DOC201 HOT 1
- False positive DOC405 HOT 2
- False positive 403 with "yield from" statement
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pydoclint.