-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Mypy day to day tips/tricks #971
Comments
For 1, on Linux, you can do: while inotifywait -e close_write filename.py; do mypy filename.py; done |
Thanks @kirbyfan64, that should do the trick. I looked more into 3, is it possibly because the libraries I am importing don't have stub files? For larger projects like numpy/sklearn/etc, do you know if the plan on adding them, or is it a better idea to write a few short ones for only the things I use? I also maintain a library I would like to write stub files for, anything I should know beyond the docs? |
3: You can try using the 4: Properly type checking code using numpy (and many third party modules) is currently not supported. Numpy, in particular, would require some new type system features and is not trivial to support. This is something I'd like to have but we don't have resources to work on this in the near future, and other modules like SQLAlchemy, Flask and Tornado are higher on the priority list :-( |
About 3:
Could it be possible to add an option to not check for modules, or simply assume all modules exist and all methods on these modules exist and are valid? I'm using mypy with Syntastic inside vim, and I think it is impossible to make it stop complaining. |
You can try adding |
More about 3: You can always annotate every import with missing stub using
We don't have a perfect story for missing stub files. Here are some things we could consider:
(The number is 1000 is, of course, totally arbitrary and we could choose any reasonable number.) Any thoughts about these? |
Thank you very much! I'm pretty happy with these solutions for ignoring modules (but surely my use-case is simple and modest). |
Something similar has been done before with JS and TypeScript and wanted to make a note about it. Its not realistic to contribute type definitions upstream to JavaScript libraries that already exist, so they have DefinitlyTyped, their github is at https://github.com/DefinitelyTyped/DefinitelyTyped. They made it into a community effort and its pretty successful for them. They also have a package manager for definitions: http://definitelytyped.org/tsd/ |
For PEP 484 we have typeshed: https://github.com/python/typeshed -- it's
shared between mypy, pytype, and PyCharm.
|
Let's close this. I think most ideas here have been implemented or have their own issue tracking them. If you disagree, please open a new issue for specific issues. |
I am just starting to use mypy and PEP484 type hints since I was tired of not having types to reason about/auto check. I am wondering what do common users have in their day to day use that makes it easier.
The docs point primarily to
mypy filename.py
.Is there a way to run it on a module or specify something like(foundmypy packagename/*.py
to run on everything (I know this could be done with a bash script, but builtin would be nice).-m
, but it doesn't seem to be returning any errors at all)No module named 'modulename'
which are pip packages I have installed like numpy, sklearn, etc. How can you fix this?np.array
asAny
, is there a good workaround for this, or is it a bug?For some of these things, I would be willing to contribute a patch if it doesn't exist already.
The text was updated successfully, but these errors were encountered: