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-101552: Allow pydoc to display signatures in source format by JelleZijlstra · Pull Request #124669 · python/cpython

Conversation

@JelleZijlstra

@JelleZijlstra JelleZijlstra commented Sep 27, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Add a annotations_format argument to inspect.signature, matching annotationlib.Format
  • Add an unquote_annotations argument to inspect.Signature.format, allowing string annotations to be displayed without quotes
  • Use the new functionality in pydoc to display signatures in source format.
  • Issue: The builtin help(...) should unstringify (and "unforwardref") annotations #101552

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

Sorry, something went wrong.

Uh oh!

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

All reactions
JelleZijlstra added 4 commits September 26, 2024 22:24
@JelleZijlstra
pythongh-101552: Add format argument to inspect.signature
f806791
And use the STRING format in pydoc.
@JelleZijlstra
Merge remote-tracking branch 'upstream/main'
4e319cf
@JelleZijlstra
fixes
38c4b42
@JelleZijlstra
Merge remote-tracking branch 'upstream/main' into sigdocs
c33c4cc
@JelleZijlstra
JelleZijlstra requested a review from larryhastings September 27, 2024 13:23
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 27, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Sep 27, 2024
The builtin help(...) should unstringify (and "unforwardref") annotations #101552
Closed
JelleZijlstra added 3 commits September 27, 2024 06:38
@JelleZijlstra
missing file
9c7b972
@JelleZijlstra
blurb
b14a719
@JelleZijlstra
format -> annotation_format
33ef93d
@JelleZijlstra
JelleZijlstra requested review from AlexWaygood and carljm September 27, 2024 18:33
carljm
carljm approved these changes Sep 27, 2024
View reviewed changes
Comment thread Lib/test/test_inspect/test_inspect.py
ida = inspect_deferred_annotations
sig = inspect.Signature
par = inspect.Parameter
PORK = inspect.Parameter.POSITIONAL_OR_KEYWORD

@carljm carljm Sep 27, 2024

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.

🐷

Sorry, something went wrong.

Uh oh!

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

AlexWaygood and efimov-mikhail reacted with heart emoji
All reactions
  • ❤️ 2 reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Sep 27, 2024
AlexWaygood
AlexWaygood approved these changes Sep 27, 2024
View reviewed changes

@AlexWaygood AlexWaygood left a comment

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.

Nice! Some nitpicks, but nothing blocking really

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/inspect.rst Resolved

Uh oh!

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

Comment thread Doc/library/inspect.rst Outdated
:func:`copy.replace`.

.. method:: format(*, max_width=None)
.. method:: format(*, max_width=None, unquote_annotations=False)

@AlexWaygood AlexWaygood Sep 27, 2024

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.

This doesn't feel like a totally correct use of "unquote" to me... Maybe the parameter could be called remove_annotation_quotes instead of unquote_annotation...? I think that might also reflect slightly better the fact that not all annotations will necessarily be quoted at all.

Sorry, something went wrong.

Uh oh!

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

All reactions

@JelleZijlstra JelleZijlstra Sep 27, 2024

Copy link
Copy Markdown
Member 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.

We use "unquote" in various other places (e.g., https://docs.python.org/3.13/library/csv.html#csv.QUOTE_NOTNULL); I feel it's more clear and concise

Sorry, something went wrong.

Uh oh!

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

All reactions

@AlexWaygood AlexWaygood Sep 27, 2024

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.

"unquoted" is used in https://docs.python.org/3.13/library/csv.html#csv.QUOTE_NOTNULL as an adjective rather than a verb. I think it makes sense to talk about something being "unquoted" but less sense to talk about "unquoting" something.

Sorry, something went wrong.

Uh oh!

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

All reactions

@larryhastings larryhastings Sep 30, 2024

Copy link
Copy Markdown
Contributor

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.

"dequote"?

Sorry, something went wrong.

Uh oh!

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

All reactions

@larryhastings larryhastings Sep 30, 2024

Copy link
Copy Markdown
Contributor

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.

If I'm reading the code correctly, if this is false (the default) we use repr on annotation values that are strings, and if it's true we skip repr only for strings. So this is a passive operation--if the value is true, we don't do something, and when it's false we do do something. I think that's why this is awkward.

I suggest the clearest way to express this is to flip it. Negate the boolean and rename it quote_annotations=True. If it's true (the default) we quote annotations, and if it's false we don't. I might even go with the wordier quote_annotation_strings=True, as we're only allowing the user to control quoting or not-quoting the annotations when they're strings. But I don't have a strong opinion about that.

Sorry, something went wrong.

Uh oh!

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

All reactions

@JelleZijlstra JelleZijlstra Oct 1, 2024

Copy link
Copy Markdown
Member 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.

Good idea, changing that.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/inspect.rst Resolved

Uh oh!

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

Comment thread Doc/whatsnew/3.14.rst Resolved

Uh oh!

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

Comment thread Lib/inspect.py Resolved

Uh oh!

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

Comment thread Lib/inspect.py Resolved

Uh oh!

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

Comment thread Lib/inspect.py Resolved

Uh oh!

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

@JelleZijlstra @AlexWaygood
Apply suggestions from code review
afdf4fc
Co-authored-by: Alex Waygood <[email protected]>
AlexWaygood
AlexWaygood reviewed Sep 27, 2024
View reviewed changes
Comment thread Lib/inspect.py Resolved

Uh oh!

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

@JelleZijlstra @AlexWaygood
Update Lib/inspect.py
1549080
Co-authored-by: Alex Waygood <[email protected]>
larryhastings
larryhastings reviewed Sep 30, 2024
View reviewed changes
Comment thread Doc/library/inspect.rst Outdated
attempt to automatically un-stringize the annotations using
:func:`annotationlib.get_annotations`. The
*globals*, *locals*, and *eval_str* parameters are passed
*globals*, *locals*, *eval_str*, and *annotation_format* parameters are passed

@larryhastings larryhastings Sep 30, 2024

Copy link
Copy Markdown
Contributor

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.

It's a minor thing, but: globals, locals, and eval_str are passed in to parameters with the same name when calling get_annotations. But annotation_format is passed in to a parameter with a different name (just format). It might be nice to explicitly tell that to the user.

I realize the documentation doesn't explicitly detail where these parameters go, so this would be all-new text. And when I try it in my head it always comes across as clumsy. So... should we even bother to try? Would anybody be confused if we didn't bother to explain it?

Sorry, something went wrong.

Uh oh!

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

All reactions

@JelleZijlstra JelleZijlstra Oct 1, 2024

Copy link
Copy Markdown
Member 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.

Good point, I will add a separate sentence about the annotation_format parameter.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/inspect.rst Outdated
:func:`copy.replace`.

.. method:: format(*, max_width=None)
.. method:: format(*, max_width=None, unquote_annotations=False)

@larryhastings larryhastings Sep 30, 2024

Copy link
Copy Markdown
Contributor

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.

If I'm reading the code correctly, if this is false (the default) we use repr on annotation values that are strings, and if it's true we skip repr only for strings. So this is a passive operation--if the value is true, we don't do something, and when it's false we do do something. I think that's why this is awkward.

I suggest the clearest way to express this is to flip it. Negate the boolean and rename it quote_annotations=True. If it's true (the default) we quote annotations, and if it's false we don't. I might even go with the wordier quote_annotation_strings=True, as we're only allowing the user to control quoting or not-quoting the annotations when they're strings. But I don't have a strong opinion about that.

Sorry, something went wrong.

Uh oh!

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

All reactions
JelleZijlstra added 2 commits September 30, 2024 21:14
@JelleZijlstra
Merge remote-tracking branch 'upstream/main' into sigdocs
5831cc4
@JelleZijlstra
Renamings
35ee105
JelleZijlstra
JelleZijlstra commented Oct 9, 2024
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2024-09-27-06-39-32.gh-issue-101552.xYkzag.rst Resolved

Uh oh!

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

JelleZijlstra added 2 commits October 8, 2024 21:38
@JelleZijlstra
Update Misc/NEWS.d/next/Library/2024-09-27-06-39-32.gh-issue-101552.x…
c549c70
…Ykzag.rst
@JelleZijlstra
Merge branch 'main' into sigdocs
e448b82
@JelleZijlstra
JelleZijlstra enabled auto-merge (squash) October 9, 2024 04:39
@JelleZijlstra
JelleZijlstra merged commit 7840638 into python:main Oct 9, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 9, 2024
efimov-mikhail pushed a commit to efimov-mikhail/cpython that referenced this pull request Oct 9, 2024
@JelleZijlstra @AlexWaygood @efimov-mikhail
pythongh-101552: Allow pydoc to display signatures in source format (p…
8192c63
…ython#124669)

Co-authored-by: Alex Waygood <[email protected]>
@JelleZijlstra JelleZijlstra mentioned this pull request Nov 17, 2024
bpo-39990: try resolving type hints in pydoc #19874
Closed
qtprojectorg pushed a commit to pyside/pyside-setup that referenced this pull request May 23, 2025
@luk1337
pyi_generator.py: Pass all args/kwargs to original formatannotation()
7882518
Python 3.14 changed formatannotation() function signature by adding `*,
quote_annotation_strings=True` at the end of it.

Since we only care about avoiding `text.removeprefix('typing.')`, let's
just pass extra args/kwargs as is to keep compatibility with < 3.14.

[1] python/cpython#124669

Change-Id: Ic115ed5cc8766cdf60286e88f6cfa79e263f64c9
Reviewed-by: Łukasz Patron <[email protected]>
Reviewed-by: Christian Tismer <[email protected]>
Reviewed-by: Friedemann Kleint <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@larryhastings larryhastings larryhastings left review comments
@AlexWaygood AlexWaygood AlexWaygood approved these changes
@carljm carljm carljm approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@JelleZijlstra @carljm @larryhastings @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 01402520 — 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.