-
-
Notifications
You must be signed in to change notification settings - Fork 30.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
Proposal: Convert the typing
-module PEPs into a series of HOWTOs
#91533
Comments
typing
-module PEPs into a series of HOWTOstyping
-module PEPs into a series of HOWTOs
(In case it's not obvious: I'm happy to invest time and energy into writing some of these, if we agree that this is a good solution to the problem.) |
I would invite you to have this discussion over at https://github.com/python/typing/issues. The documentation over there (which is currently published to https://typing.readthedocs.io) is intended to be the comprehensive source for typing related documentation. There already are a few issues about a possible structure on that site. Fragmenting the existing documentation even more should not be the goal. readthedocs was chosen for an easy to set-up documentation target. Eventually integrating the documentation with docs.python.org should be a goal, though. |
Also cc @shannonzhu who set up a lot of the infrastructure of the typing docs. |
The core issue, in my opinion, is that the One possible alternative solution to the problem, as you say, is to invest energy into further expanding the documentation at https://typing.readthedocs.io/, and link heavily to that corpus of documentation from the docs at https://docs.python.org/3/library/typing.html. |
This sounds great to me! One argument for typing.readthedocs.io is that a lot of the information is not tied to Python versions, or is usable from third-party backport modules. (I'm just throwing ideas around, not arguing a position. Please consider them, but you don't need to convince me.) |
Thanks for starting this effort! I'd been thinking about working on this area too. In my mind, there are several different goals we could work towards:
These two perhaps shouldn't be the same document. A spec is useful for advanced users, but for most users it's not the right place to start. I'd want to focus on the spec, for a couple of reasons: it's easier since we can mostly glue together the spec sections of the PEPs; it allows us to change the spec in the future (which we sometimes want to do); and there are already excellent documentation resources online (e.g., the mypy docs). So here's what I'd want to see:
I don't feel too strongly about where to put the spec or docs. typing.readthedocs.io is nice but we haven't made much progress with it and it's true that it may be less discoverable. |
I'll cross-reference the related issue over at the python/typing repo, so that people can have a more full consideration of the (slightly competing, but I think/hope also somewhat complementary 🙂) proposals: |
+1 for looking to the mypy docs as an example -- they're a really impressive body of typing documentation. I'd be wary of linking to them too heavily, though, as they are also becoming outdated in places -- we'd effectively be relying on a third-party project having well-maintained documentation. mypy also can't document any typing features that they don't yet support, whereas CPython should document the latest typing features, even if they are not yet supported by all type-checkers (and full support of new typing features by third-party type checkers can often take >1 year). |
Would it make sense to kick-start the typing docs for end users by selectively copying sections from the mypy docs (with some kind of attribution)? Just like starting the specs with the existing PEPs. |
I guess I'm not 100% sold on the distinction between specifications and end-user documentation. I get the idea, but I worry that we'll end up with duplication between the different pieces of documentation. For example, PEP 544 is mostly a specification. But I've also seen it remarked upon in several places (e.g. here, or here) that it serves as an excellent piece of end-user documentation, which is better than anything currently at https://docs.python.org/3/library/typing.html. |
I agree that it would be useful to collect a set of official “typing Guides/HOWTOs”, which are distinct from the typing-related PEPs (which are deltas applied on top of each other). I agree that the mypy documentation would be a good starting point for this effort. This is the documentation that I currently consult first for guide-level typing documentation. I don’t particularly care where such guide level documentation lives. I do think, however that it might be best suited to be in a site external from the versioned Python documentation, since type annotations are mostly agnostic to whatever Python version is in use. (In particular you can use very new typing features in older versions of Python.) I do think, however that typing.rst from the Python documentation should include prominent links to this external site (at least to the site’s top-level) to make it discoverable (both by users and search engines). I am aware of the existing https://typing.readthedocs.io/en/latest/ site. A cursory reading of that site’s current content feels it is currently used to house detailed typing related documentation that didn’t already make it into a PEP or somewhere else (like the mypy documentation). For example it details the handling of It would make sense to me to focus this documentation effort on improving the content at the existing https://typing.readthedocs.io/en/latest/ site, and linking it to from the official versioned Python documentation when the site is deemed “ready” (for some definition of “ready”). Also, I like the organization of guides proposed by the originator of this thread. ( @AlexWaygood ) |
It sounds like the prevailing mood is to invest energy into improving the corpus of documentation at typing.readhedocs.io, and then — once they're ready — link heavily from I still have some concerns about the discoverability of typing.readhedocs.io. Does anybody have any idea why it fares so poorly in Google results? Is this just due to the fact that it's a fairly new site, with few external sites linking to it? How can we improve the situation? I hate the idea of investing large amounts of energy into writing typing docs, only for no one to see them. |
Don’t worry about SEO. If what we place there is good, readers will come. |
@AlexWaygood I think once we have a fairly stable and good set of documentation on typing.readhedocs.io (and we are a long way off), we should look into moving some or all of it over to docs.python.org, but until then we are more free to experiment. I'd also like to merge your proposal here, the proposal in python/typing#845, and the "proposal" in https://github.com/python/typing/blob/master/docs/index.rst and https://github.com/python/typing/tree/master/docs/source into a coherent whole. |
Sure, but I also think we're in rough agreement about the place we want to end up at now, so it's probably time to stop talking about writing and start writing 🙂 we can debate the finer points of "what goes in which document" at a later date. With that in mind:
I'm thinking we can incrementally delete chunks from |
@encukou, would the docs working group/community be interested in helping review these pieces of documentation as and when they're ready? |
I'd be happy to. For my own reference: This initiative appears relevant to Python 3.11 documentation and therefore is more urgent than Python 3.12 items I'm already scheduled for, such as TypeForm/AnnotationType. So I'll probably pick it up next (in my queue of Python-related tasks). |
Most likely. Please open an issue at https://github.com/python/docs-community/issues when you're ready for the review! |
Please please please please please!! I am SO in need of this! (I can't possibly be the only newcomer who feels the same way) |
@AlexWaygood I would love to add this to use cases: I would also love if another link to the |
From a 30,000-foot view, this certainly feels like it would be a net win for both sides. |
After re-reading |
Actually, us new users are saying we don't know where to look:
If we don't know where to go, we can't come...
Providing a new user perspective, what I'm lacking is HOW-TO design principles. These arguably come with experience, but this knowledge is beginning to be needed more and more by new users:
If a "business need" is what's required, I feel fairly safe in claiming you could probably grep the issue tracker and discussions for "that's working as intended" compared with actual bugs and find the percentage of the former greatly outweighs the latter. Regardless of all of that, I think you'll find new users do want to learn the right way of doing things. I'm certainly in that camp. I want to know how to type hint properly and I want to be able to point others to a proper reference so I don't spread misinformation. However a HOW-TO can be achieved, I am extremely in favor of it. |
See the discussion at python#91533
…GH-96921) See the discussion at python#91533 (cherry picked from commit 5b3a256) Co-authored-by: Shantanu <[email protected]>
…#96921) See the discussion at python#91533 (cherry picked from commit 5b3a256)
…ythonGH-96921) See the discussion at python#91533. (cherry picked from commit 5b3a256) Co-authored-by: Shantanu <[email protected]>
…ythonGH-96921) See the discussion at python#91533. (cherry picked from commit 5b3a256) Co-authored-by: Shantanu <[email protected]>
See the discussion at #91533 (cherry picked from commit 5b3a256) Co-authored-by: Shantanu <[email protected]>
) (GH-96937) See the discussion at #91533. (cherry picked from commit 5b3a256) Co-authored-by: Shantanu <[email protected]>
See the discussion at #91533 (cherry picked from commit 5b3a256) Co-authored-by: Shantanu <[email protected]>
…eatures' document
Problem description
The
typing
module docs have a problem.typing.rst
is littered with references to the many typing-related PEPs that have been accepted by the Steering Council. Often these references to PEPs are used in lieu of detailed examples or explanation as to how a feature is supposed to work.However, PEPs are not supposed to be living pieces of documentation. As such, proposals to update old typing PEPs to reflect changes in implementation details have been rejected. But when these PEPs are the closest thing we have to a full Python-typing specification, this means that our specifications are slowly growing out of date.
This unfortunate situation has also been recognised by the Steering Council in a recent email to the typing-sig mailing list.
Proposed solution
I propose that we slowly start to convert various typing PEPs into a series of Python-typing HOWTOs. In this way, we'd follow the example of other modules such as
enum
orsocket
. These modules have terse API references insocket.rst
andenum.rst
, but these API references are supplemented with expansive HOWTOs that serve as a guide for users who are new to the respective modules. Given the number of typing PEPs, the scale of the task for typing will be larger; but I still believe that this is a good example to follow.Specifically, I think we should have something like the following structure:
ClassVar
)typing.Self
)typing.rst
onAny
,Callable
and type aliases.typing.rst
onTypeVar
and generics (but only the most basic material).typing.Generic
to make generic classes.ParamSpec
andConcatenate
(material from PEP 612).typing.rst
on structural subtyping andtyping.Protocol
.TypedDict
intyping.rst
.typing.Literal
) & 675 (typing.LiteralString
).Due to the brevity of their PEPs, and the fact that they don't really "fit in" neatly with any of the other proposed HOWTOs, I propose that the following typing features have their full specifications integrated into the
typing.rst
API reference, rather than having dedicated HOWTOs:Final
/@final
(PEP 581)Annotated
(PEP 593)TypeGuard
(PEP 647)Why not have this information at typing.readthedocs.io?
There's an ongoing effort, spearheaded by @srittau among others, to include a body of
typing
documentation at https://typing.readthedocs.io/en/latest/. I am fully in support of this effort, and see the documentation there as complementary to the documentation that currently lives in thetyping
PEPs. However, I do not believe that the documentation currently in thetyping
PEPs should belong on that site, for several reasons:typing
PEPs are officially recognised changes to the language and the language's typing framework. As such, -- in my opinion -- it should live in the central docs.python.org documentation along with the documentation for the rest of the language.Questions to be discussed
typing.rst
into a terser API reference?Copied to:
typing
module maintainers: @gvanrossum, @Fidget-Spinner, @JelleZijlstraLinked PRs
typing.rst
to a new 'Guide to typing features' document #105827The text was updated successfully, but these errors were encountered: