Comments (11)
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.
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.
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.
@kevinjqliu Yes, you're right, that was just me mis-remembering the API. I meant rewrite_Generator
, not visit_Generator
.
from monkeytype.
Note that these aren't fully equivalent. Generators have a close()
method but iterators don't.
from monkeytype.
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.
from monkeytype.
Done: python/mypy#4424
from monkeytype.
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.
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.
Yes, that’s right!
from monkeytype.
Related Issues (20)
- ValueError: source code string cannot contain null bytes
- New release HOT 2
- Compare observed types to existing type annotations HOT 1
- Empty lists result in overly broad types HOT 1
- Issue with Callable type for < Python 3.9 HOT 3
- Better documentation for how to use MonkeyType with multiple processes/threads HOT 3
- Collect types for non-module functions HOT 1
- provide a type rewriter to find common base class HOT 5
- how open Instagram without password
- Adding an index to monkeytype.sqlite3 speeds up stub generation HOT 1
- Keyword-only arguments are not captured in traces
- Calls to locally defined functions are not captured
- `*args` and `**kwargs` are not captured in traces HOT 1
- Add pre-commit support HOT 1
- `AttributeError: 'ellipsis' object has no attribute '__qualname__'` HOT 1
- pep_563 flag creates imports that don't match the usage of the name HOT 4
- Support PEP 585 - list[int] instead of typing.List[int]
- Stubs with positional-only args output too many slashes and cause a SyntaxError
- Error when parameter in external file is class defined in `__main__` HOT 1
- Return type not traced when returning constant (Python ≥ 3.12)
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 monkeytype.