-
-
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
Document PEP 585, 563, 604 and more. #9763
Conversation
Fixes python#8629, fixes python#8523 This creates a new page to document issues arising from discrepancies between the runtime and annotations. I felt this was better, rather than force-fitting things into existing pages and "common issues", for instance, it prevents us from having to explain PEP 563 in several different places. I do still list the runtime errors you'd get in the "common issues" page to preserve SEO :-) "String literal types", "Class name forward references", and "Import cycles" are basically the same as where they were copied over from. This also factors out the documentation of PEP 604 that I promised when merging that PR (it seemed pretty verbose, particularly for the "kinds of types" page). It's also a good place to document PEP 613, when we get around to supporting that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look great! Runtime issues are sometimes painful to deal with, and it's a good to have them all covered in one place. Left a bunch of minor comments (mostly nits).
three tools at our disposal: | ||
|
||
* For Python 3.7 through 3.9, use of ``from __future__ import annotations`` | ||
(:pep:`563`), made the default in Python 3.10 and later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since 3.10 is not out yet, this would be better written as "... will be the default in Python 3.10 and later".
|
||
Python 3.5.1 and below don't have :py:data:`~typing.TYPE_CHECKING`. An | ||
alternative is to define a constant named ``MYPY`` that has the value | ||
``False`` at runtime. Mypy considers it to be ``True`` when type checking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a short example of how this works here?
Using X | Y syntax for Unions | ||
----------------------------- | ||
|
||
Starting with Python 3.10 (:pep:`604`), you can spell union types as ``x: int | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "... you will be able to spell", since Python 3.10 is not out yet.
Thanks, made changes everywhere that I marked a conversation as resolved. The two things I haven't done are:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates! Looks good now. I agree with your reasoning, and other changes I proposed aren't important.
Fixes #8629, fixes #8523. This creates a new page to document issues arising from discrepancies between the runtime and annotations. I felt this was better, rather than force-fitting things into existing pages and "common issues", for instance, it prevents us from having to explain PEP 563 in several different places. I do still list the runtime errors you'd get in the "common issues" page to preserve SEO :-) "String literal types", "Class name forward references", and "Import cycles" are basically the same as where they were copied over from. This also factors out the documentation of PEP 604 that I promised when merging that PR (it seemed pretty verbose, particularly for the "kinds of types" page). It's also a good place to document PEP 613, when we get around to supporting that. Resolves #9856. Co-authored-by: hauntsaninja <>
Fixes #8629, fixes #8523
This creates a new page to document issues arising from discrepancies
between the runtime and annotations. I felt this was better, rather than
force-fitting things into existing pages and "common issues", for
instance, it prevents us from having to explain PEP 563 in several
different places.
I do still list the runtime errors you'd get in the "common issues" page
to preserve SEO :-)
"String literal types", "Class name forward references", and "Import
cycles" are basically the same as where they were copied over from.
This also factors out the documentation of PEP 604 that I promised when
merging that PR (it seemed pretty verbose, particularly for the "kinds
of types" page). It's also a good place to document PEP 613, when we get
around to supporting that.