On 03/12/2021 19:32, Adam Johnson wrote:
The first unwelcome surprise was:
>>> def func(a=>[]):
... return a
...
>>> import inspect
>>> inspect.signature(func).parameters['a'].default
Ellipsis
Here the current behaviour of returning `Ellipsis` is very unfortunate,
and I think could lead to a lot of head scratching — people wondering
why they are getting ellipses in their code, seemingly from nowhere.
Sure, it can be noted in the official documentation that `Ellipsis` is
used as the indicator of late bound defaults, but third-party resources
which aim to explain the uses of `Ellipsis` would (with their current
content) leave someone clueless.
+1.
This may be a very naive question, apologies if it's nonsense.
Instead of Ellipsis, would it be possible to have a built-in LateBound
class and use instances of that class instead of Ellipsis?
The __str__ method of the inspect.Parameter class could be modified to
return something like
"a=>[]"
(or whatever syntax is adopted for specifying late-bound defaults) in
such cases.
The __repr__ and __str__ methods of a LateBound object could return
something like, respectively,
"LateBound('[]')"
"[]"
I am sure there is code that uses inspect.signature that would be
broken, but isn't that inevitable anyway?
Best wishes
Rob Cliffe
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/EIVQYDWKJWW3YPSV3UMLXFMTLAEFHETW/
Code of Conduct: http://python.org/psf/codeofconduct/