Comments (6)
Hi @ddelange , did you check out the page that's included at the end of the error message: https://jsh9.github.io/pydoclint/notes_generator_vs_iterator.html
Do you think what the page says makes sense?
from pydoclint.
Hi @jsh9 👋
It should definitely be legal to annotate the above function as Iterator[int]
. The return statement is only present for (early) exit, not to actually return a value (which would need to be mentioned in the docstring). This example only ever yields an int.
From python docs:
In a generator function, the return statement indicates that the generator is done and will cause StopIteration to be raised. The returned value (if any) is used as an argument to construct StopIteration and becomes the StopIteration.value attribute.
from pydoclint.
I just ran into this as well and without a way to disable errors line by line I've had to remove pydoclint from my pre-commit
from pydoclint.
What do you think of the following logic?
- If there is a bare
return
(i.e., justreturn
without anything behind it, not evenreturn None
), suppress DOC405 - As long as there is anything after
return
, raise DOC405
The purpose of DOC405 is to persuade users to use a Generator when they are actually returning something. And I guess this use case of yours is an edge case.
from pydoclint.
sounds good:) typing docs corroborate this approach: Generator[int, None, None]
may be typed as Iterator[int]
.
since return None
and return
are equivalent statements, both fall under this category imo, and some linters might force either of both for style.
from pydoclint.
@jsh9 I think that sounds good. I actually went back and baselined with the error to get it suppressed so I'm actually good, but would love to get rid of the baseline!
from pydoclint.
Related Issues (20)
- 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 2
- False positive DOC201 HOT 1
- False positive 403 with "yield from" statement HOT 1
- Check for missing or incorrectly formatted docstring HOT 1
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.