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-119180: Rename parameter to __annotate__ functions#124461

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

Closed

Conversation

@JelleZijlstra
Copy link
Member

@JelleZijlstraJelleZijlstra commentedSep 24, 2024
edited by bedevere-appbot
Loading

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

Cross-refpython/peps#3993.

Larry Hastings pointed out that using an illegal parameter name makesit impossible to use inspect.signature() on annotate functions.Cross-refpython/peps#3993.
self.assertEqual(f.__name__,"__annotate__")

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

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?

Copy link
MemberAuthor

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.

Copy link
Member

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.)

Copy link
MemberAuthor

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__).

Copy link
Member

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__?

AlexWaygood reacted with thumbs up emoji
@JelleZijlstra
Copy link
MemberAuthor

Merged#124730 instead.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@carljmcarljmcarljm approved these changes

@iritkatrieliritkatrieliritkatriel left review comments

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@JelleZijlstra@carljm@iritkatriel

[8]ページ先頭

©2009-2025 Movatter.jp