On Wed, Oct 27, 2021 at 11:36 AM Alex Waygood <alex.waygood@gmail.com> wrote:
a <callable: (int, int) -> int>
I like this option best of the ones Guido gave (though I don't like the colon — but that's a minor nit). It's readable and consistent with the repr() of `inspect.Signature` objects. It's also clear, however, that it's representing something different from `inspect.Signature`.
I wonder, though: does this feature have any use cases outside of type-hinting/variable annotations? If not, should the repr of these objects have some indication of that? A newbie to Python might (understandably) assume from this repr that these objects are... callable. Having the word "callable" in the repr might also breed confusion with the builtin `callable` function, as well, perhaps?
Not sure I can think of anything better, however.
One reason why I am favoring the first or second option is that we already have other types whose repr() is exactly what you enter (or at least a normalized version). In particular, repr(list[int]) == "list[int]", and so for all generic builtins, per PEP 585. (And these follow the PEP 484 example, since repr(typing.List[int]) == "typing.List[int]".) Indeed, PEP 604 follows the same pattern for the new union operator: repr(int | str) == "int | str". So I think we have considerable precedent here. (Generics and unions aren't used outside annotations either.) -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>