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-119180: Rename parameter to __annotate__ functions by JelleZijlstra · Pull Request #124461 · python/cpython

Conversation

@JelleZijlstra

@JelleZijlstra JelleZijlstra commented Sep 24, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Larry Hastings pointed out that using an illegal parameter name makes
it impossible to use inspect.signature() on annotate functions.

Cross-ref python/peps#3993.

  • Issue: Implement PEP 649 and PEP 749 #119180

Sorry, something went wrong.

Uh oh!

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

All reactions
@JelleZijlstra
pythongh-119180: Rename parameter to __annotate__ functions
f768678
Larry Hastings pointed out that using an illegal parameter name makes
it impossible to use inspect.signature() on annotate functions.

Cross-ref python/peps#3993.
@JelleZijlstra
JelleZijlstra requested review from carljm, iritkatriel and markshannon as code owners September 24, 2024 18:57
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 24, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Sep 24, 2024
Implement PEP 649 and PEP 749 #119180
Closed
21 of 30 tasks
@JelleZijlstra JelleZijlstra added the skip news label Sep 24, 2024
iritkatriel
iritkatriel reviewed Sep 24, 2024
View reviewed changes
Comment thread Lib/test/test_type_annotations.py
self.assertEqual(f.__name__, "__annotate__")

expected_sig = inspect.Signature(
[inspect.Parameter("__format__", inspect.Parameter.POSITIONAL_ONLY)]

@iritkatriel iritkatriel Sep 24, 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.

__format__ is already used in a different context, as a method name. Can this be confusing?

Sorry, something went wrong.

Uh oh!

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

All reactions

@JelleZijlstra JelleZijlstra Sep 24, 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.

I feel it's unlikely to cause much confusion, since the name will very rarely show up to users (only if they introspect annotate functions, which is very unlikely to happen), and in a context that doesn't have anything to do with the __format__ method.

Sorry, something went wrong.

Uh oh!

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

All reactions

@carljm carljm Sep 24, 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.

Given that we are kind of picking a name out of thin air that we expect not to matter, it seems like we might as well avoid the potential for someone thinking this is related to __format__? Would there be an issue with just using _format? (I don't feel strongly about this at all.)

Sorry, something went wrong.

Uh oh!

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

All reactions

@JelleZijlstra JelleZijlstra Sep 24, 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 should use a dundered name because dundered name are reserved to the implementation. Users could use a class named _format in their annotations.

The current PR has this behavior:

>>> def f(x: __format__): pass
... 
>>> f.__annotations__
{'x': 1}

I think with a dunder name we can handwave that away with "don't do that", but a user could reasonably use the name _format.

Still we could use a different name like __fmt__ or __annotate__ (I think Larry suggested the latter, but that name feels more confusing than __format__).

Sorry, something went wrong.

Uh oh!

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

All reactions

@carljm carljm Sep 24, 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.

Ah yeah, makes sense why it needs to be a dunder name. Given users should never have to type it, or likely see it, and the main thing we prefer to avoid is collisions with a user parameter, should we actually prefer something longer, like __annotation_format__?

Sorry, something went wrong.

Uh oh!

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

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@JelleZijlstra
fix tests
06a17db
carljm
carljm approved these changes Sep 24, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Sep 24, 2024
@JelleZijlstra

JelleZijlstra commented Dec 30, 2024

Copy link
Copy Markdown
Member Author

Merged #124730 instead.

All reactions

Sorry, something went wrong.

Uh oh!

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

@JelleZijlstra JelleZijlstra closed this Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@carljm carljm carljm approved these changes
@iritkatriel iritkatriel iritkatriel left review comments
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

awaiting merge skip news

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.

3 participants

@JelleZijlstra @carljm @iritkatriel
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.