| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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.
| self.assertEqual(f.__name__, "__annotate__") | ||
|
|
||
| expected_sig = inspect.Signature( | ||
| [inspect.Parameter("__format__", inspect.Parameter.POSITIONAL_ONLY)] |
There was a problem hiding this comment.
__format__ is already used in a different context, as a method name. Can this be confusing?
Sorry, something went wrong.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| Back | FazBrowse Home | New Git URL |
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.