Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

Re: [Python-checkins] cpython (2.7): #14804: Remove [] around optional arguments with default values

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


ncoghlan at gmail

May 22, 2012, 5:08 AM

Post #1 of 2 (93 views)
Permalink
Re: [Python-checkins] cpython (2.7): #14804: Remove [] around optional arguments with default values

On Tue, May 22, 2012 at 6:34 PM, hynek.schlawack
<python-checkins [at] python> wrote:
> http://hg.python.org/cpython/rev/a36666c52115
> changeset:   77102:a36666c52115
> branch:      2.7
> parent:      77099:c13066f752a8
> user:        Hynek Schlawack <hs [at] ox>
> date:        Tue May 22 10:27:40 2012 +0200
> summary:
>  #14804: Remove [] around optional arguments with default values
>
> Mostly just mechanical removal of []. In some rare cases I've pulled the
> default value up into the argument list.

Be a little careful with this - "[]" is the right notation when the
function doesn't support keyword arguments. At least one of the
updated signatures is incorrect:

> diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
> --- a/Doc/library/itertools.rst
> +++ b/Doc/library/itertools.rst
> @@ -627,7 +627,7 @@
>                   break
>
>
> -.. function:: tee(iterable[, n=2])
> +.. function:: tee(iterable, n=2)

>>> itertools.tee([], n=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: tee() takes no keyword arguments

Since calling "tee(itr, n=2)" doesn't add really any clarity over
"tee(itr, 2)", it's unlikely this function will ever gain keyword
argument support (since supporting keyword arguments *is* slower than
supporting only positional arguments for functions written in C.

The change is probably valid for the pure Python modules, and the
builtins looked right, but be wary of any extension modules in the
list.

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan [at] gmail   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


hs at ox

May 22, 2012, 5:38 AM

Post #2 of 2 (90 views)
Permalink
Re: [Python-checkins] cpython (2.7): #14804: Remove [] around optional arguments with default values [In reply to]

Hi Nick,

>> Mostly just mechanical removal of []. In some rare cases I've pulled the
>> default value up into the argument list.
> Be a little careful with this - "[]" is the right notation when the
> function doesn't support keyword arguments. At least one of the
> updated signatures is incorrect:

Ah dang, thanks for pointing this out! I went at least five times
through all changes but there had to be one thing I missed. :(

Same in dl.open() & ossaudiodev.oss_audio_device.setparameters(). I will
go through them all once more and fix it at the latest tomorrow.

Regards,
Hynek
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.