Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Larry Hastings pointed out that using an illegal parameter name makesit impossible to use inspect.signature() on annotate functions.Cross-refpython/peps#3993.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import annotationlib | ||
| import inspect | ||
| import textwrap | ||
| import types | ||
| import unittest | ||
| @@ -266,6 +267,17 @@ def check_annotations(self, f): | ||
| f.__annotations__ = {"z": 43} | ||
| self.assertIs(f.__annotate__, None) | ||
| def test_annotate_function_signature(self): | ||
| def f(x: int): pass | ||
| anno = f.__annotate__ | ||
| self.assertIsInstance(anno, types.FunctionType) | ||
| self.assertEqual(f.__name__, "__annotate__") | ||
| expected_sig = inspect.Signature( | ||
| [inspect.Parameter("__format__", inspect.Parameter.POSITIONAL_ONLY)] | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 The current PR has this behavior: I think with a dunder name we can handwave that away with "don't do that", but a user could reasonably use the name Still we could use a different name like Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| ) | ||
| self.assertEqual(inspect.signature(anno), expected_sig) | ||
| class DeferredEvaluationTests(unittest.TestCase): | ||
| def test_function(self): | ||