Skip to content

[3.10] bpo-46769: Improve documentation for typing.TypeVar (GH-31712)#31941

Merged
JelleZijlstra merged 5 commits into
python:3.10from
AlexWaygood:backport-81b425d-3.10
Mar 23, 2022
Merged

[3.10] bpo-46769: Improve documentation for typing.TypeVar (GH-31712)#31941
JelleZijlstra merged 5 commits into
python:3.10from
AlexWaygood:backport-81b425d-3.10

Conversation

@AlexWaygood

@AlexWaygood AlexWaygood commented Mar 16, 2022

Copy link
Copy Markdown
Member

Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com
(cherry picked from commit 81b425d)

This PR backports GH-31712 to 3.10. However, two key modifications have been made:

  • References to reveal_type (new in 3.11) have been removed.
  • A new section, illustrating how to use bound TypeVars to annotate alternative-constructor classmethods, has been added. This is one of the most important uses of bound TypeVars for Python versions <=3.10, but is no longer needed in 3.11 due to the addition of typing.Self.

https://bugs.python.org/issue46769

…H-31712)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 81b425d)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@AlexWaygood AlexWaygood changed the title [3.10] bpo-46769: Improve documentation for typing.TypeVar (GH-31712) [3.10] bpo-46769: Improve documentation for typing.TypeVar (GH-31712) Mar 16, 2022
@AlexWaygood AlexWaygood added docs Documentation in the Doc dir skip news needs backport to 3.9 labels Mar 16, 2022

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, good call on the additional example

Comment thread Doc/library/typing.rst Outdated
Comment thread Doc/library/typing.rst Outdated
@JelleZijlstra JelleZijlstra self-assigned this Mar 17, 2022

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! (Also cc @rhettinger since we're mentioning him in these docs.)

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @AlexWaygood for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @AlexWaygood and @JelleZijlstra, I could not cleanly backport this to 3.9 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker d5ed8a8258eaf7a241978b1b0aeb971108d0f7e0 3.9

JelleZijlstra pushed a commit to JelleZijlstra/cpython that referenced this pull request Mar 23, 2022
…ythonGH-31712) (pythonGH-31941)

* [3.10] bpo-46769: Improve documentation for `typing.TypeVar` (pythonGH-31712)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 81b425d)

* Remove references to `reveal_type`, add new section on `self` types.
(cherry picked from commit d5ed8a8)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-32067 is a backport of this pull request to the 3.9 branch.

@AlexWaygood AlexWaygood deleted the backport-81b425d-3.10 branch March 23, 2022 05:02
ambv pushed a commit that referenced this pull request Mar 23, 2022
GH-31941) (GH-32067)

* [3.9] [3.10] bpo-46769: Improve documentation for `typing.TypeVar` (GH-31712) (GH-31941)

* [3.10] bpo-46769: Improve documentation for `typing.TypeVar` (GH-31712)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 81b425d)

* Remove references to `reveal_type`, add new section on `self` types.
(cherry picked from commit d5ed8a8)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* remove unused susp allowlist

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
…-31712) (pythonGH-31941) (pythonGH-32067)

* [3.9] [3.10] bpo-46769: Improve documentation for `typing.TypeVar` (pythonGH-31712) (pythonGH-31941)

* [3.10] bpo-46769: Improve documentation for `typing.TypeVar` (pythonGH-31712)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 81b425d)

* Remove references to `reveal_type`, add new section on `self` types.
(cherry picked from commit d5ed8a8)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

* remove unused susp allowlist

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants