GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-105286: Improve `typing.py` docstrings by AlexWaygood · Pull Request #105287 · python/cpython Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @@ -1,20 +1,21 @@ | |||
| """ | |||
| The typing module: Support for gradual typing as defined by PEP 484. | |||
| The typing module: Support for gradual typing as defined by PEP 484 and subsequent PEPs. | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Many other PEPs have revised the typing spec since PEP 484
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Any, NoReturn, Never, ClassVar, Union, Optional, Concatenate, Unpack | ||
| * Classes whose instances can be type arguments in addition to types: | ||
| ForwardRef, TypeVar and ParamSpec | ||
| NoReturn, Never, ClassVar, Self, Concatenate, Unpack, and others. | ||
| * Classes whose instances can be type arguments: | ||
| TypeVar, ParamSpec, TypeVarTuple. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Any is now its own class, rather than being an instance of _SpecialForm_SpecialForms have now been added. Rather than attempting to list them all (which would just go out of date again), I've just added "and others" at the end of an abbreviated list.ForwardRef aren't actually accepted by type checkers as type annotations, as far as I know, so that was somewhat confusing here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * Public helper functions: get_type_hints, overload, cast, no_type_check, | ||
| no_type_check_decorator. | ||
| * Generic aliases for collections.abc ABCs and few additional protocols. | ||
| * Public helper functions: get_type_hints, overload, cast, final, and others. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Many other public helper functions have been added that aren't listed here, so I just made it an abbreviated list and put "and others" at the end
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| _collect_parameters((T, Callable[P, T])) == (T, P) | ||
| assert _collect_parameters((T, Callable[P, T])) == (T, P) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Guido mentioned in #101827 that he didn't like this style of code example, where it's not really a REPL example, but also isn't something you'd ever put in an executable .py file either. I agree that using an explicit assert is better for this kind of code example.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| There is no runtime checking of these properties. The decorator | ||
| sets the ``__final__`` attribute to ``True`` on the decorated object | ||
| to allow runtime introspection. | ||
| attempts to set the ``__final__`` attribute to ``True`` on the decorated |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If AttributeError or TypeError is encountered, the __final__ attribute won't be set.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Alternative equivalent keyword syntax is also accepted:: | ||
|
|
||
| Employee = NamedTuple('Employee', name=str, id=int) | ||
| An alternative equivalent functional syntax is also accepted:: | ||
|
|
||
| Employee = NamedTuple('Employee', [('name', str), ('id', int)]) |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is a partial revert of #104945.
#104945 removed any mention of the functional syntax from this docstring. I agree with removing the mention of Python 3.5 from the docstring (also done in #104945), but I disagree with removing any mention of the functional syntax. The functional syntax is supported by type checkers, and still quite common in many codebases.
However, I do think we should remove any mention of the keyword-argument syntax, since this way of creating NamedTuples isn't supported by any type checker that I know of.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, two minor comments
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Shantanu <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| no_type_check_decorator. | ||
| * Generic aliases for collections.abc ABCs and few additional protocols. | ||
| * Public helper functions: get_type_hints, overload, cast, final, and others. | ||
| * Deprecated aliases for collections.abc ABCs. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
All points except this one have examples. Is it intentional?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yeah, they're deprecated ;p
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Nikita Sobolev <[email protected]>
Co-authored-by: Nikita Sobolev <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the improvements!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @AlexWaygood, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry @AlexWaygood, I had trouble checking out the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Shantanu <[email protected]> Co-authored-by: Nikita Sobolev <[email protected]>
|
GH-105319 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
gh-105286: Improve `typing.py` docstrings (#105287) Co-authored-by: Shantanu <[email protected]> Co-authored-by: Nikita Sobolev <[email protected]>
|
GH-105322 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
pythongh-105286: Improve `typing.py` docstrings (python#105287) Co-authored-by: Shantanu <[email protected]> Co-authored-by: Nikita Sobolev <[email protected]>
Co-authored-by: Shantanu <[email protected]> Co-authored-by: Nikita Sobolev <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.