On Sat, Dec 4, 2021 at 11:59 AM Rob Cliffe via Python-ideas <python-ideas@python.org> wrote: > > > > On 03/12/2021 22:38, Chris Angelico wrote: > > On Sat, Dec 4, 2021 at 8:18 AM Rob Cliffe via Python-ideas > > <python-ideas@python.org> wrote: > >> > >> > >> 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? > >> > > That's a possibility for the inspect module. For the core language - > > and therefore for anything that directly inspects the function's > > dunders - it's much more efficient to use a well-known object. > OK. > I'm guessing that by "well-known" you mean pre-existing. Python has a > number of built-in singleton objects (None, True, False, Ellipsis).
Mainly by "well-known" I mean "not private to any particular module", so those four you mention are all well-known, but a singleton as part of the inspect module would be a pain, since the core language would have to import that (or it would have to be magically created). > What about adding a new one called LateBound (or other bikeshed colour)? What would be gained? You would still be able to use LateBound as an early-bound default, so you would still need the same dual check. With inspect.Parameter, you already have a repr and str that show that it's late-bound, exactly like you suggest. What advantage is there from using a dedicated sentinel instead of Ellipsis? It wouldn't be too hard to change the inspect module, but I'd need to know why. ChrisA _______________________________________________ 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/N3CBJ6A22PBINFUTSE3YPQQFOSDAERJD/ Code of Conduct: http://python.org/psf/codeofconduct/