GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-104010: Separate and improve docs for `typing.get_origin` and `typing.get_args` by chgnrdv · Pull Request #104013 · python/cpython

Conversation

@chgnrdv

@chgnrdv chgnrdv commented Apr 30, 2023 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #104010

  • separate documentation and examples for both functions
  • add examples demonstrating behaviour with unsupported types
  • Issue: typing: Document get_origin and get_args separately #104010

📚 Documentation preview 📚: https://cpython-previews--104013.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@chgnrdv
typing: separate and improve docs for get_origin and get_args
f6a2736
* separate documentation and examples for both functions
* add examples demonstrating behaviour with unsupported types
@chgnrdv
chgnrdv requested review from AlexWaygood, Fidget-Spinner, JelleZijlstra and gvanrossum as code owners April 30, 2023 14:49
@bedevere-bot bedevere-bot added docs Documentation in the Doc dir skip news labels Apr 30, 2023
@bedevere-bot bedevere-bot mentioned this pull request Apr 30, 2023
typing: Document get_origin and get_args separately #104010
Closed
@bedevere-bot bedevere-bot added the awaiting review label Apr 30, 2023
@JelleZijlstra JelleZijlstra added the needs backport to 3.11 only security fixes label Apr 30, 2023
@AlexWaygood AlexWaygood added the topic-typing label Apr 30, 2023
JelleZijlstra
JelleZijlstra reviewed Apr 30, 2023
View reviewed changes
Comment thread Doc/library/typing.rst Outdated

Get the unsubscripted version of a type: for a typing object of the form
``X[Y, Z, ...]`` return ``X``. If ``X`` is a generic alias for a builtin or
:mod:`collections` class, it gets normalized to the original class.

@JelleZijlstra JelleZijlstra Apr 30, 2023

Copy link
Copy Markdown
Member

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.

Let's add that for ParamSpecArgs and Kwargs, it returns the underlying ParamSpec.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@chgnrdv chgnrdv Apr 30, 2023

Copy link
Copy Markdown
Contributor Author

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.

Done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JelleZijlstra JelleZijlstra Apr 30, 2023

Copy link
Copy Markdown
Member

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!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@chgnrdv
documented return value of get_origin for ParamSpecArgs and `Para…
6009b6b
…mSpecKwargs` instances
JelleZijlstra
JelleZijlstra reviewed Apr 30, 2023
View reviewed changes
Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Update Doc/library/typing.rst
e3a1b63
JelleZijlstra
JelleZijlstra approved these changes Apr 30, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Apr 30, 2023
@chgnrdv
removed doubleticks
83dd082
@chgnrdv

chgnrdv commented Apr 30, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Shouldn't get_args and get_origin docs be swapped? Also get_args doc uses "objects" to denote unsupported typing objects, but in get_origin doc I wrote "types". Is it critical?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra

JelleZijlstra commented Apr 30, 2023

Copy link
Copy Markdown
Member

Good points, I do think it makes sense to put get_origin first.

I'd standardize on objects: these things work on objects that aren't strictly types, like Required[]

AlexWaygood and chgnrdv reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

chgnrdv added 2 commits April 30, 2023 18:23
@chgnrdv
Merge branch 'typing-separate-and-improve-get_args-get_origin-docs' o…
e733947
…f github.com:chgnrdv/cpython into typing-separate-and-improve-get_args-get_origin-docs
@chgnrdv
swapped get_args and get_origin docs, changed "objects" to "types…
d53b595
…" in `get_origin` doc
@JelleZijlstra
JelleZijlstra merged commit a7a2dbb into python:main May 10, 2023
@miss-islington

miss-islington commented May 10, 2023

Copy link
Copy Markdown
Contributor

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

chgnrdv reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label May 10, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 10, 2023
@chgnrdv @JelleZijlstra @miss-islington
pythongh-104010: Separate and improve docs for typing.get_origin an…
8555c1a
…d `typing.get_args` (pythonGH-104013)

* separate documentation and examples for both functions
* add examples demonstrating behaviour with unsupported types
* document return value of `get_origin` for `ParamSpecArgs` and `ParamSpecKwargs` instances

(cherry picked from commit a7a2dbb)

Co-authored-by: chgnrdv <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
@bedevere-bot

bedevere-bot commented May 10, 2023

Copy link
Copy Markdown

GH-104359 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label May 10, 2023
JelleZijlstra added a commit that referenced this pull request May 10, 2023
@miss-islington @chgnrdv @JelleZijlstra
[3.11] gh-104010: Separate and improve docs for typing.get_origin a…
a8e902d
…nd `typing.get_args` (GH-104013) (#104359)

* separate documentation and examples for both functions
* add examples demonstrating behaviour with unsupported types
* document return value of `get_origin` for `ParamSpecArgs` and `ParamSpecKwargs` instances

(cherry picked from commit a7a2dbb)

Co-authored-by: chgnrdv <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
carljm added a commit to carljm/cpython that referenced this pull request May 10, 2023
@carljm
Merge branch 'main' into fixloadsuperspec
5976df9
* main:
  pythonGH-102181: Improve specialization stats for SEND (pythonGH-102182)
  pythongh-103000: Optimise `dataclasses.asdict` for the common case (python#104364)
  pythongh-103538: Remove unused TK_AQUA code (pythonGH-103539)
  pythonGH-87695: Fix OSError from `pathlib.Path.glob()` (pythonGH-104292)
  pythongh-104263: Rely on Py_NAN and introduce Py_INFINITY (pythonGH-104202)
  pythongh-104010: Separate and improve docs for `typing.get_origin` and `typing.get_args` (python#104013)
  pythongh-101819: Adapt _io._BufferedIOBase_Type methods to Argument Clinic (python#104355)
  pythongh-103960: Dark mode: invert image brightness (python#103983)
  pythongh-104252: Immortalize Py_EMPTY_KEYS (pythongh-104253)
  pythongh-101819: Clean up _io windows console io after pythongh-104197 (python#104354)
  pythongh-101819: Harden _io init (python#104352)
  pythongh-103247: clear the module cache in a test in test_importlib/extensions/test_loader.py (pythonGH-104226)
  pythongh-103848: Adds checks to ensure that bracketed hosts found by urlsplit are of IPv6 or IPvFuture format (python#103849)
  pythongh-74895: adjust tests to work on Solaris (python#104326)
  pythongh-101819: Refactor _io in preparation for module isolation (python#104334)
  pythongh-90953: Don't use deprecated AST nodes in clinic.py (python#104322)
  pythongh-102327: Extend docs for "url" and "headers" parameters to HTTPConnection.request()
  pythongh-104328: Fix typo in ``typing.Generic`` multiple inheritance error message (python#104335)
carljm added a commit to carljm/cpython that referenced this pull request May 11, 2023
@carljm
Merge branch 'main' into supermon
19b3d9e
* main: (27 commits)
  pythongh-87849: fix SEND specialization family definition (pythonGH-104268)
  pythongh-101819: Adapt _io.IOBase.seek and _io.IOBase.truncate to Argument Clinic (python#104384)
  pythongh-101819: Adapt _io._Buffered* methods to Argument Clinic (python#104367)
  pythongh-101819: Refactor `_io` futher in preparation for module isolation (python#104369)
  pythongh-101819: Adapt _io.TextIOBase methods to Argument Clinic (python#104383)
  pythongh-101117: Improve accuracy of sqlite3.Cursor.rowcount docs (python#104287)
  pythonGH-92184: Convert os.altsep to '/' in filenames when creating ZipInfo objects (python#92185)
  pythongh-104357: fix inlined comprehensions that close over iteration var (python#104368)
  pythonGH-90208: Suppress OSError exceptions from `pathlib.Path.glob()` (pythonGH-104141)
  pythonGH-102181: Improve specialization stats for SEND (pythonGH-102182)
  pythongh-103000: Optimise `dataclasses.asdict` for the common case (python#104364)
  pythongh-103538: Remove unused TK_AQUA code (pythonGH-103539)
  pythonGH-87695: Fix OSError from `pathlib.Path.glob()` (pythonGH-104292)
  pythongh-104263: Rely on Py_NAN and introduce Py_INFINITY (pythonGH-104202)
  pythongh-104010: Separate and improve docs for `typing.get_origin` and `typing.get_args` (python#104013)
  pythongh-101819: Adapt _io._BufferedIOBase_Type methods to Argument Clinic (python#104355)
  pythongh-103960: Dark mode: invert image brightness (python#103983)
  pythongh-104252: Immortalize Py_EMPTY_KEYS (pythongh-104253)
  pythongh-101819: Clean up _io windows console io after pythongh-104197 (python#104354)
  pythongh-101819: Harden _io init (python#104352)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes
@gvanrossum gvanrossum Awaiting requested review from gvanrossum
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner
@AlexWaygood AlexWaygood Awaiting requested review from AlexWaygood AlexWaygood is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir skip news topic-typing

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

typing: Document get_origin and get_args separately

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@chgnrdv @JelleZijlstra @miss-islington @bedevere-bot @AlexWaygood
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.