On Fri, Dec 3, 2021 at 8:07 AM David Mertz, Ph.D. <david.me...@gmail.com> wrote:
>
> On Thu, Dec 2, 2021 at 2:40 PM Chris Angelico <ros...@gmail.com> wrote:
>>
>> How is a late-bound default different from half of a conditional expression?
>
>
>>
>>  def f(lst=>[], n=>len(lst)):
>>
>>
>> def f(*args):
>>     lst = args[0] if len(args) > 0 else []
>>     n = args[1] if len(args) > 1 else len(lst)
>
>
> Although such is obviously not your intention, I think you have provided a 
> stronger argument against this feature/PEP than any other I've seen raised so 
> far.  Well, maybe just against the specific implementation you have in mind.
>

Fascinating.

> You are correct, of course, that the second form does not provide 
> inspectability for `lst` and `n`.  Well, it does, but only in a fairly 
> contorted way of disassembling f.__code__.co_code.  Or maybe with an equally 
> indirect look at the parse tree or something.  The body of a function is very 
> specifically A BODY.
>
> What your proposal/implementation does is put things into the function 
> signature that are simultaneously excluded from direct inspectability as 
> function attributes. Python, like almost all programming languages, makes a 
> pretty clear distinction between function signatures and function bodies.  
> You propose to remove that useful distinction, or at least weaken it.
>

Actually, no. I want to put the default arguments into the signature,
and the body in the body. The distinction currently has a technical
restriction that means that, in certain circumstances, what belongs in
the signature has to be hacked into the body. I'm trying to make it so
that those can be put where they belong.

> For the reasons Eric Smith and others have pointed out, I really WANT to keep 
> inspectability of function signatures.
>

Here's what you get:

>>> def f(lst=>[], n=>len(lst)): ...
...
>>> f.__defaults_extra__
('[]', 'len(lst)')

String representation, but exactly what the default is. Any tool that
inspects a signature (notably, help() etc) will be able to access
this.

Now write the function the other way, and show me how easy it is to
determine the behaviour when arguments are omitted. What can you
access?

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/2RZBMRT5RPHCSRW67GPGEF44E2SHG4ZB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to