Comments (14)
How about something like this?
❯ monkeytype list-modules | xargs -n1 monkeytype apply
from monkeytype.
+1 monkeytype apply somemod --recursive
from monkeytype.
I've been using this command to create a file for all possible stubs:
monkeytype list-modules | xargs -n1 -I{} sh -c 'monkeytype stub {} > stubs/{}.pyi'
from monkeytype.
The stubs would be used by the IDE or other tools.
from monkeytype.
Good idea!
from monkeytype.
@thedrow - How are you imagining that this would be used? For most projects the number of generated stubs will likely be too large to be consumable in a useful manner.
from monkeytype.
@mpage Not all projects are that big :-) I've worked on plenty of projects in the past with module counts in the tens, rather than hundreds or thousands, where it would be reasonable to just want to apply all types and fix all type errors in a single go (but there are still enough modules that it would be a pain to run monkeytype separately for each one.) A couple further thoughts:
- I can easily envision how this would work for
monkeytype apply
, not so much formonkeytype stub
, since we currently dump stubs directly to stdout. I think any multi-module output mode would need to create a directory tree on disk instead. - I think it might be better to think of it as a recursive mode (like
monkeytype apply somemod --recursive
, which would apply to all submodules as well) rather than--all
. The latter just makes things really dependent on having the right code filter in place at tracing time, otherwise it gets totally out of hand.
I don't think I'm likely to work on this, but to me it seems interesting enough to warrant leaving the issue open.
from monkeytype.
Just a suggestion to use
monkeytype stub .
form
from monkeytype.
@msoedov Thanks for the suggestion! Can you clarify what semantics you'd envision for monkeytype apply .
? Would it try to apply all stubs present in the trace store? Or all stubs for modules within the current working directory (recursively)? The dot suggests the latter to me.
It seems like one downside of this suggestion is that it's less flexible; unlike a -r
flag, it doesn't generalize to picking any module and applying all stubs within it, recursively. IOW it doesn't have any equivalent for monkeytype apply some.module -r
.
from monkeytype.
Is anyone working on --recursive / -r option? If not, I can take a crack at it. Any opinions on implementation?
from monkeytype.
@johnarnold I'm not aware of anyone working on it, take it away!
from monkeytype.
Any progress on this? Even just being able to pass multiple modules to be annotated in a single pass would be really useful (as it should avoid the overhead of needing to read in the database, which for larger projects can be substantial).
from monkeytype.
I'm not aware that anyone is working on this currently. If you'd like to work on it, pull requests are welcome! IMO either "allow passing multiple modules to apply" or "add --recursive option to apply" are reasonable design options. In either case stub
would remain unchanged.
from monkeytype.
I use this powershell script on Windows:
$modules = monkeytype list-modules
New-Item -Path "stubs" -ItemType Directory -ErrorAction Ignore
foreach ($module in $modules) {
$stub = monkeytype stub $module
$stub | Out-File -FilePath "stubs/$module.pyi" -Force
}
from monkeytype.
Related Issues (20)
- 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
- `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)
- monkeytype apply seems to attempt to import my whole program, causing monkeytype: error: unrecognized arguments:
- checking instagrm password
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.