[Python-ideas] Positional-only parameters

Stephan Houben stephanh42 at gmail.com
Thu Mar 2 02:41:17 EST 2017


Hi all,

I have a slight variant of the decorator proposal.
Rather than specify a count, let the decorator implement the typeshed
dunder convention:

@positional_only
    def replace(self, __old, __new, count=-1):

(I imagine this decorator would also treat "self" as position_only,
so no need for __self.)

Pros:
1. Consistent with the typeshed convention.
2. Avoids a count.
3. Strictly opt-in, so hopefully keeps those @#?! underscore
preservationists from picketing my lawn (again!).

Stephan



2017-03-02 4:16 GMT+01:00 Chris Barker <chris.barker at noaa.gov>:

> On Wed, Mar 1, 2017 at 2:16 PM, אלעזר <elazarg at gmail.com> wrote:
>
>> I like the idea, but I wanted to note that since it has no meaning from
>> the point of view of the defined function, it can be done with a magic
>> decorator, so new syntax is not required:
>>
>> @positional_only[:4]
>> def replace(self, old, new, count=-1):
>>     ...
>>
>
> I"m confused, what does the [:4] mean?
>
> if you want old and new to be positional only, wouldn't it be something
> like:
>
> @positional_only(3)
>     def replace(self, old, new, count=-1):
>         ...
>
> i.e. the first three parameters are positional only.
>
> and why indexing/slice syntax???
>
> +! on the idea -- still on the fence about syntax.
>
> -CHB
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170302/1e23c45f/attachment.html>


More information about the Python-ideas mailing list