-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Think through a strategy for documenting Mypy and the type system #1262
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
Comments
Thanks! This sounds like a great plan. Eventually I expect that we'll have to have several separate docs on the type hints: formal reference docs describing the type system exactly and formally, and (somewhat) informal user docs that take users through the various parts of the type system, discussing warts and patterns for common situations. Also, I think that we soon will have to come up with a way to add features to typing.py that are (at least initially) exclusive to mypy, so that mypy can develop somewhat faster than the PEP approval process. Note that feedback and suggested improvements to the PEP (whether they're purely editorial or might require a formal discussion on python-{ideas,dev}) should start off as issues on the https://github.com/python/typing/ tracker. |
Yeah, that division may also make sense. I think of splitting documentation mainly in terms of who the audience is: people implementing the type system for Mypy, PyCharm, pytype, and other tools need one form of documentation, people who have gotten started writing type hints and are now doing so need another form, and people who are just getting started need a third form. I think the core Python documentation, in the Language Reference and Library Reference, are a very successful model for the "user who's already gotten started" category, which is also generally the highest-volume category: there are many more users than implementors, and a user spends much more time already past the introductory stage than in it. The style is pretty formal and specific, but readable, and doesn't always nail things 100% down. So my hope is that a Type Hints Reference would be in the same style and similarly effective for that role. The Language Reference and parts of the Library Reference also serve the "implementor" category to some degree, but that use case isn't stressed hard for Python because CPython is so well-established and dominant that in practice its accidental behavior is almost as important for other implementations' compatibility as any documented behavior. For type hints we'll need a more consciously formal and 100% exact document, even at the expense of readability. I think we might evolve PEP 484 into that document; if that doesn't make sense in the PEP format, I definitely agree we should find a way to have it somewhere. For core Python, my experience has been that a lot of the role of "informal user docs" is actually served well by the Language Reference and the Library Reference, so I'd hope for a Type Hints Reference in a similar style to accomplish that as well. The main exception is for users just getting started. The Python Tutorial and a number of resources on the web serve that for core Python; we'll definitely want something for type hints as well. Because that tends to benefit from hands-on examples, I wonder if it might do best in the context of a particular tool, like as a Mypy tutorial. |
All very reasonable. PEP 484 was originally meant to be the formal 100% On Wed, Mar 2, 2016 at 11:54 AM, Greg Price [email protected]
--Guido van Rossum (python.org/~guido) |
We have two main bodies of documentation right now:
mypy
type-checker tool. It describes the system in more narrative fashion aimed at someone writing type annotations, and it describes details that aren't specified in the PEP. This is much like how for most Python language features, developers generally refer to the Python Language Reference rather than a corresponding PEP.We've arrived at this setup through a particular historical path, and there are some things that aren't great about it. As we continue to improve the documentation, we should work out what set of bodies of documentation we'd like to have, and how to move toward that.
Here's one setup that I think would improve some things:
mypy
tool itself. This would focus on the CLI and the workflow specific to the type-checker, plus any Mypy-specific details that are too involved to put into a "Mypy only" box in the Type Hints Reference. (The latter might then have a box that mostly just links to the relevant section of this document.) Perhaps the "Mypy Usage Reference"? A quick-start or tutorial section might have some small annotation examples in order to be self-contained for its purpose, but the bulk of the work of documenting how to write annotations would be left to the Type Hints Reference, which this would just link to.A good first draft of the Python Type Hints Reference and Mypy Usage Reference might come from just taking the existing Mypy documentation and pulling it apart into two documents. Most of it would land in the Type Hints Reference, I think, and the Mypy Usage Reference would be relatively short.
The big value of making this distinction, though, comes if we can make the Python Type Hints Reference function as shared documentation across all the tools that implement PEP 484, including PyCharm and pytype, with the same kind of shared status as the PEP itself -- playing a role complementary to the PEP by addressing annotation-writers rather than implementors, having a more narrative style with more examples, and being readily editable with a low-friction pull-request workflow to continuously improve as exposition.
In particular:
The text was updated successfully, but these errors were encountered: