Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-105286: Improvetyping.py docstrings#105287

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

AlexWaygood
Copy link
Member

@AlexWaygoodAlexWaygood commentedJun 4, 2023
edited by bedevere-bot
Loading

Copy link
MemberAuthor

@AlexWaygoodAlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Inline justifications for some of the changes:

@@ -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.
Copy link
MemberAuthor

Choose a reason for 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

Lib/typing.py Outdated
Comment on lines 8 to 10
Any,NoReturn, Never, ClassVar,Union, Optional,Concatenate, Unpack
* Classes whose instances can be type arguments in addition to types:
ForwardRef, TypeVar andParamSpec
NoReturn, Never, ClassVar,Self,Concatenate, Unpack, and others.
* Classes whose instances can be type arguments:
TypeVar,ParamSpec, TypeVarTuple.
Copy link
MemberAuthor

Choose a reason for 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
  • Numerous other_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.
  • Instances ofForwardRef aren't actually accepted by type checkers as type annotations, as far as I know, so that was somewhat confusing here.

* 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.
Copy link
MemberAuthor

Choose a reason for 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

Lib/typing.py Outdated
Comment on lines 254 to 255
_collect_parameters((T, Callable[P, T])) == (T, P)
assert_collect_parameters((T, Callable[P, T])) == (T, P)
Copy link
MemberAuthor

Choose a reason for 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 explicitassert is better for this kind of code example.


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
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

IfAttributeError orTypeError is encountered, the__final__ attribute won't be set.

Comment on lines -2725 to +2727
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)])
Copy link
MemberAuthor

@AlexWaygoodAlexWaygoodJun 4, 2023
edited
Loading

Choose a reason for 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, Ido think we should remove any mention of the keyword-argument syntax, since this way of creatingNamedTuplesisn't supported by any type checker that I know of.

Copy link
Contributor

@hauntsaninjahauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good to me, two minor comments

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Copy link
Member

@sobolevnsobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks!

Lib/typing.py Outdated
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.
Copy link
Member

Choose a reason for 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?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, they're deprecated ;p

Copy link
Member

@JelleZijlstraJelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for all the improvements!

AlexWaygood reacted with rocket emoji
@AlexWaygoodAlexWaygoodenabled auto-merge (squash)June 5, 2023 13:54
@AlexWaygoodAlexWaygood merged commitf714aa2 intopython:mainJun 5, 2023
@miss-islington
Copy link
Contributor

Thanks@AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry,@AlexWaygood, I could not cleanly backport this to3.12 due to a conflict.
Please backport usingcherry_picker on command line.
cherry_picker f714aa2c29eae5cc4b5b54e4d83d83eebd5eac53 3.12

@miss-islington
Copy link
Contributor

Sorry@AlexWaygood, I had trouble checking out the3.11 backport branch.
Please retry by removing and re-adding the "needs backport to 3.11" label.
Alternatively, you can backport usingcherry_picker on the command line.
cherry_picker f714aa2c29eae5cc4b5b54e4d83d83eebd5eac53 3.11

@AlexWaygoodAlexWaygood deleted the improve-typing-docstrings branchJune 5, 2023 14:19
AlexWaygood added a commit to AlexWaygood/cpython that referenced this pull requestJun 5, 2023
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-bot
Copy link

GH-105319 is a backport of this pull request to the3.12 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.12only security fixes labelJun 5, 2023
AlexWaygood added a commit that referenced this pull requestJun 5, 2023
gh-105286: Improve `typing.py` docstrings (#105287)Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-bot
Copy link

GH-105322 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelJun 5, 2023
AlexWaygood added a commit to AlexWaygood/cpython that referenced this pull requestJun 5, 2023
pythongh-105286: Improve `typing.py` docstrings (python#105287)Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
ambv pushed a commit that referenced this pull requestJun 5, 2023
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sobolevnsobolevnsobolevn left review comments

@hauntsaninjahauntsaninjahauntsaninja left review comments

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

@gvanrossumgvanrossumAwaiting requested review from gvanrossum

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-Spinner

Assignees

@AlexWaygoodAlexWaygood

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@AlexWaygood@miss-islington@bedevere-bot@JelleZijlstra@sobolevn@hauntsaninja

[8]ページ先頭

©2009-2025 Movatter.jp