-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Facilitate easy integration of mypy in other tools: use mypy as a module and obtain the results as structured data rather than flat text. #2097
Comments
Thanks for the trust you're placing in mypy. We've received a few similar
requests, and we've always said "it's too early, don't try to use mypy as a
library, everything will change in an incompatible way". But maybe we
should start thinking seriously about an API. So no, you're not missing
anything, and mypy.main.type_check_only() is probably the best API we
currently have (though I suspect we'll eventually rename it to
"type_check()" and move it to a module to be named mypy.api).
Regarding access to a less textual version of the error messages, if you
haven't already, please read the file mypy/errors.py. The representation is
all there. Accessing it after type_check_only() returns is a not ideal; I
think res.manager.errors should do it, unless type_check_only() raises
CompilationError (which is a terrible design -- we should really get rid of
it).
Maybe you can design a more straightforward API and send it to us as a PR?
|
I am not sure I already have enough insight in mypy to succesfully design an API for it, but I plan to give it a try. The approach I have in mind is to leave the current source code of mypy as it is and graft a separate API upon it, indeed in a module mypy.api The accent will be on the 'outside view' of the API, so how exactly it is connected with the (changing) backend I will consider secondary, although as a proof of concept I'll try to make a provisional connection. It may very well be that I overstretch my understanding of mypy in attempting this, in which case I'll report back in this issue. |
Sounds like a plan. Looking forward to it!
…--Guido (mobile)
|
Pull request #2114 makes available the API. I already use it in Transcrypt, where it does a proper job. |
It would be great to have a specific API for the type inference capabilities of mypy. I imagine feeding this API with a typed_ast and getting inferred types for relevant nodes. This is very useful for powerful static analysis, allowing the implementation of even smarter linters for Python. Not sure if this is tracked by another issue already, looked for it but couldn't find. |
Yes, that would be very useful and powerful. It would also be complicated to implement and maintain, so this isn't something we're expecting to be working on in the near (or even medium) future. |
This would be great to have at some point for integration in a REPL (like ptpython). Besides getting structured output, it would be good if the input could be a string containing the code snippet, rather than filename. |
Hi
First of all thanks for this project. Saying this isn't merely a formality. I've grown up with C++. Dynamic typing in Python gives a lot of development speed but, and I really like the language for it, but sometimes rigorous typechecks save a lot of time and on top of that help me to understand the source code much more easily.
I've been attempting to integrate mypy in my Transcrypt Python to JavaScript compiler with some success, although I am only at the beginning of understanding the consequences and improving the interaction. The purpose is to make Transcrypt a serious alternative for Typescript.
Since Transcrypt itself is written in Python 3.5, it only seemed logical to use mypy as a module rather than starting it up as a separate process / application.
I now face two design questions for which I only found a provisional answer.
This leaves me with the following startup code, greatly inspired by function main of mypy's mypy/main.py:
My issues are the following
Kind regards
Jacques de Hooge
The text was updated successfully, but these errors were encountered: