[Python-ideas] Positional only arguments
Ron Adam
rrr at ronadam.com
Fri May 18 17:41:48 CEST 2007
Ron Adam wrote:
> Fred L. Drake, Jr. wrote:
>> On Thursday 17 May 2007, George Sakkis wrote:
>> > single "delimiter" symbol (e.g. '%') between pos-only and pos-or-kw
>> > would kill both birds with one stone, i.e. something like:
>>
>> A delimeter that would be needed anyway would make this a little nicer:
>>
>> def myfunc(a, b, c=24; *, kw=42):
>> pass
>>
>> This example would have 3 positional-only arguments (a, b, c) and one
>> keyword-only argument (kw).
>>
>> Replacing the comma with a semicolon avoids the need for a syntax-only
>> position (good, IMO), avoids introducing a new special character, and re-uses
>> one that's rarely used anyway.
>
>
> [A few thoughts]
>
> def foo([positonal_only_args][; [kwd_args][; kwds_only]]): ...
>
> def myfunct(a, b, c=42; e=99; kw=42): ...
Hmmm, this has a problem if you use * or ** in the definition. :(
def myfunc(*args; ? ; **kwds): ...
I think this would be an issue with some of the other ideas as well.
> args = (1, 2, 3, 4) # 'e' can be in either args or kwds,
> kwds = {'kw': 42} # but not both.
>
> bar = foo(*args, **kwds)
>
>
> How about signature objects that are similar to slice objects?
>
> sig = signature(*args, **kwds) # Pre package signature.
> sig = signature(1, 2, 3, 4, kw=42)
>
> Could something like this have performance benefit if the same exact
> signature is used over and over? Possibly just passing a pre parsed name
> space to the function?
>
> bar = foo(sig) # No need to unpack with * or **.
>
> bar = foo(@sig) # Be lenient, extra args and kwds
> # are consumed or ignored.
> # But always error if something is missing.
>
> The '@' sign is like a vortex which sucks up unused args. ;-)
>
> Ron
More information about the Python-ideas
mailing list