Giter Site home page Giter Site logo

False positive DOC405 about pydoclint HOT 6 OPEN

ddelange avatar ddelange commented on June 21, 2024
False positive DOC405

from pydoclint.

Comments (6)

jsh9 avatar jsh9 commented on June 21, 2024

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.

ddelange avatar ddelange commented on June 21, 2024

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.

jabbera avatar jabbera commented on June 21, 2024

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.

jsh9 avatar jsh9 commented on June 21, 2024

Hi @jabbera and @ddelange ,

What do you think of the following logic?

  • If there is a bare return (i.e., just return without anything behind it, not even return 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.

ddelange avatar ddelange commented on June 21, 2024

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.

jabbera avatar jabbera commented on June 21, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.