Code Monkey home page Code Monkey logo

Comments (6)

sanmai-NL avatar sanmai-NL commented on July 17, 2024 1

Don't raise NotImplementedError (class) but NotImplementedError() (instance).

from vulture.

jakkdl avatar jakkdl commented on July 17, 2024 1

It's not documented in the README, but you can suppress unreachable-code errors for a line with noqa: V201. Vulture should perhaps handle this case automatically though.

from vulture.

kreathon avatar kreathon commented on July 17, 2024

Just randomly reading this.

but we need the yield statement there to make the method into a generator!

May I ask what the yield makes for a difference? So where does it break if it is missing? Runtime, type checking, other static checkers or just that the developer knows about it?

I am just asking such that I can think about other possible solutions.

from vulture.

Zac-HD avatar Zac-HD commented on July 17, 2024

Runtime (e.g. inspect.isgeneratorfunction() as well as static typechecking. I guess it's also useful for human readers but the runtime requirement is the hard one.

from vulture.

kreathon avatar kreathon commented on July 17, 2024

I agree that that type checker and code readability can probably easily be managed (type annotation, custom decorator, custom exception).

For runtime checks I thought about the following:

class AbstractFoo(ABC):
    @abstractmethod
    def some_generator(self):
        yield from GeneratorNotImplemented()

where GeneratorNotImplemented is something like

class GeneratorNotImplemented:
    def __init__(self):
        raise NotImplementedError

However, I guess it it less readable than the original code.

Sorry, if this goes into a wrong direction for you. I am not maintainer of this project.

Bye the way, the more I think about it, the more sense it makes to me to not mark them as unreachable yields (similar to yield followed by a return to create an empty iterator). Because the yield was put there on purpose and changes the behavior of the program.

I also checked mypy and PyCharm both of them will mark the code as unreachable (like vulture).

from vulture.

jfcherng avatar jfcherng commented on July 17, 2024

Here's another use case. I don't force a child class to implement the method and I have a default empty one.

    def my_generator(self) -> Generator[str, None, None]:
        return
        yield  # I have to add "noqa: V201"

from vulture.

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.