-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Initial version of API module #2114
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
Conversation
Thanks for giving it a shot. In my personal opinion this API is too complex and too constraining for mypy's implementation. I'd like to propose something simpler, closer to the command line. You'd pass it a list of files (or possibly files and directories) plus an Options object (see mypy/options.py) and it returns a possibly-empty list of tuples describing errors with the same format as returned by render_messages() in mypy/errors.py. What would you think of that? It's less likely to be stable forever, but I think it's too early to commit to an API that's entirely future-proof. So I'd like to give you something that's just short of having to parse the errors from a subprocess. PS. If you submit an implementation of that, could you please use docstrings instead of long comments? |
Hi, thanks for the feedback While in the long run I think an error class hierarchy is a good idea, because it makes it easy catch specific errors first and then have a wider net for the more general ones, it may be too specific and restricting now. So I'll take a look at using tuples as you propose, as well as passing in an Options object as a whole, rather than separate options. Can you clarify a bit more what you mean by 'closer to the command line'? Since you propose to use an Options object, it's my understanding that you do not want to use the command line switch syntax to pass in options. Or do I misunderstand you here? Which aspect of the API would you like to be closer to the command line? About comments versus docstrings: I will adapt them. |
I just meant that the Options object is a pretty good representation of Regarding syntax highlighters, it's not just your syntax highlighter that On Mon, Sep 12, 2016 at 11:09 PM, Jacques de Hooge <[email protected]
--Guido van Rossum (python.org/~guido) |
This seems to be lingering. I'm closing it now, since we're not going with this version. If you have a new version, please just open a new PR. Thanks! |
OK, I am rather busy these days. But it's still on my to do list. |
No problem. Hope to hear from you soon!
|
Hi,
On invitation of gvanrossum I've designed a simplified API for mypy, meant to enable easy use of mypy as module rather than as stand-alone program.
The main goals in designing this API were to keep everything simple and explicit. Not all functionality of mypy is currently accessible via the API. Still this initial version at least helped me to indeed use mypy as a module in a straightforward way.
The API is non-intrusive in this sense that for this initial version deliberately no modifications were made to the rest of mypy. For easy reference, below there is a brief description of the API, that's also part of the source code:
I've tested the correct functioning of the API in the Transcrypt Python to JavaScript translator. While this test is by no means exhaustive, the API indeed provided very easy integration of mypy in Transcrypt. As an example here's the code of the Transcrypt module that uses the new mypy API and subsequently logs messages in a proprietary, hierarchical format, per file and, within that, per line.
Activating mypy is simply done in the following line (settings are just the defaults):
validationMessages = api.type_validator.validate ([sourcePath])
Everything mypy wants the world to know is in a polymorphic list returned by the validator, in a simple, non-textual format, documented explicitly in the API module, suitable for further processing. No exceptions to be caught, no special treatment or required dissection of CompileErrors, no need to read through other modules of mypy. The ValidationMessage class hierarchy can be expanded at will as mypy evolves, not changing anything to the API.
The list of ValidationMessage's is used by the surrounding code of Transcrypt as follows:
(Note that while the code below is formatted according to non-PEP standards since it coexists with C++ and JS code, the API itself follows PEP)
Kind regards
Jacques de Hooge