Git Product home page Git Product logo

Comments (11)

iyanuashiri avatar iyanuashiri commented on May 17, 2024 1

I think I understand what you want me to do. So I should create a class that inherits from TypeRewriter, with a visit_Generator method that inspects the __args__ of the Generator type?

from monkeytype.

iyanuashiri avatar iyanuashiri commented on May 17, 2024 1

Hey @carljm, I am sorry it is taking long to send a pull request. I just got a hang of your code and how to implement my solution. Initially I understood what to do but I didn't know how to do it. I will send a PR as soon as possible. Thank you for the patience.

from monkeytype.

kevinjqliu avatar kevinjqliu commented on May 17, 2024 1

TypeRewriter class with a visit_Generator

@carljm I'm confused by the naming convention. Wouldn't we want to name the new method something like rewrite_Generator because the rewrite method in TypeRewriter class will delegate to getattr(typ, 'name', None).

from monkeytype.

carljm avatar carljm commented on May 17, 2024 1

@kevinjqliu Yes, you're right, that was just me mis-remembering the API. I meant rewrite_Generator, not visit_Generator.

from monkeytype.

gvanrossum avatar gvanrossum commented on May 17, 2024

Note that these aren't fully equivalent. Generators have a close() method but iterators don't.

from monkeytype.

carljm avatar carljm commented on May 17, 2024

Hmm, good point. Perhaps that ought to be mentioned at http://mypy.readthedocs.io/en/latest/kinds_of_types.html#generators ?

In practice (at least in our codebase) I find the close() method to be rarely/never used, and Iterator[Foo] is much nicer on the eyes than Generator[Foo, None, None]. So I'd still be inclined to provide this (and probably even enable it by default). But this difference is certainly worth a mention in the docs. (It would be provided as a TypeRewriter, so if someone doesn't want it, it'd just be a small config change.)

from monkeytype.

gvanrossum avatar gvanrossum commented on May 17, 2024

from monkeytype.

carljm avatar carljm commented on May 17, 2024

Done: python/mypy#4424

from monkeytype.

iyanuashiri avatar iyanuashiri commented on May 17, 2024

Hey @carljm, I want to work on this issue. I have gone through the source code and saw a make_generator function. Is my job to change the return value from Generator[..] to Iterator[..]?

Thank you as you reply

from monkeytype.

carljm avatar carljm commented on May 17, 2024

Hi @iyanuashiri! Thanks for your interest. We could implement this feature by returning Iterator[yield_type] from make_generator in the case where send_type and return_type are both None. However, given the above discussion I don't think we should do that, because we want to make it easy for someone to opt-out of the rewriting. So instead we should provide this as a TypeRewriter class with a visit_Generator method that inspects the __args__ of the Generator type and rewrites it if the send and return types are None. And then add this new Rewriter to the default rewriter.

from monkeytype.

carljm avatar carljm commented on May 17, 2024

Yes, that’s right!

from monkeytype.

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.