Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-17 Thread Steven D'Aprano
On Thu, Jan 16, 2014 at 01:08:47PM -0800, Ryan Smith-Roberts wrote: > socket.getservbyname(servicename[, protocolname]) > > This is not an inspectable signature, since pure Python does not support > bracketed arguments. To make it inspectable, we must give protocolname a > (valid Python) default

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Larry Hastings
On 01/16/2014 01:08 PM, Ryan Smith-Roberts wrote: There are two classes of builtins whose signatures do not have these properties. The first is those with very weird signatures, like curses.window.addstr(). It's fine that those don't get converted, they're hopeless. Speaking as the father of

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 01/16/2014 04:08 PM, Ryan Smith-Roberts wrote: > [L]et us return to my original example, getservbyname(). Its current > signature: > > socket.getservbyname(servicename[, protocolname]) > > This is not an inspectable signature, since pure Python d

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Terry Reedy
On Thu, Jan 16, 2014 at 1:42 AM, Terry Reedy wrote: itertools.repeat('a', -1) repeat('a', 0) itertools.repeat('a', times=-1) repeat('a') itertools.repeat('a', times=-2) repeat('a', -2) The first line is correct in both behavior and representation. The second line behavior (and correspo

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Ryan Smith-Roberts
Let me expand on the issue, and address some of the replies. The goal of Argument Clinic is to create new docstring signatures for builtins, with the following properties: 1) Useful. While one can create a signature of func(*args) and then document complex and arbitrary restrictions on what args

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Mark Shannon
On 16/01/14 19:43, Larry Hastings wrote: On 01/16/2014 04:21 AM, MRAB wrote: On 2014-01-16 05:32, Larry Hastings wrote: [snip] We could add a special value, let's call it sys.NULL, whose specific semantics are "turns into NULL when passed into builtins". This would solve the problem but it's

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Larry Hastings
On 01/16/2014 04:21 AM, MRAB wrote: On 2014-01-16 05:32, Larry Hastings wrote: [snip] We could add a special value, let's call it sys.NULL, whose specific semantics are "turns into NULL when passed into builtins". This would solve the problem but it's really, really awful. Would it be better

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Larry Hastings
On 01/16/2014 03:38 AM, Antoine Pitrou wrote: On Wed, 15 Jan 2014 21:55:46 -0800 Larry Hastings wrote: Passing in "None" here is inconvenient as it's an integer argument. Inconvenient for whom? The callee or the caller? The callee, specifically the C argument parsing code. (Even more speci

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 01/16/2014 12:32 AM, Larry Hastings wrote: > We could add a special value, let's call it sys.NULL, whose specific > semantics are "turns into NULL when passed into builtins". This would > solve the problem but it's really, really awful. That doesn

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Guido van Rossum
On Thu, Jan 16, 2014 at 12:31 AM, Serhiy Storchaka wrote: > getattr(foo, 'bar', None) is not the same as getattr(foo, 'bar'). So None > can't be used as universal default value. Not universal, but I still think that most functions don't need to have such a subtle distinction. E.g. in the case of

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Guido van Rossum
On Thu, Jan 16, 2014 at 1:42 AM, Terry Reedy wrote: > On 1/16/2014 3:31 AM, Serhiy Storchaka wrote: >> >> 16.01.14 08:05, Guido van Rossum написав(ла): >>> >>> In this specific case it's clear to me that the special-casing of >>> negative count is intentional -- presumably it emulates sequence >>>

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread MRAB
On 2014-01-16 05:32, Larry Hastings wrote: [snip] In the specific case of SHA1_new's "string" parameter, we could lie and claim that the default value is b''. Internally we could still use NULL as a default and get away with it. But this is only a happy coincidence. Many (most?) functions lik

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Georg Brandl
Am 16.01.2014 12:39, schrieb Antoine Pitrou: > On Thu, 16 Jan 2014 04:42:43 -0500 > Terry Reedy wrote: > >> On 1/16/2014 3:31 AM, Serhiy Storchaka wrote: >> > 16.01.14 08:05, Guido van Rossum написав(ла): >> >> In this specific case it's clear to me that the special-casing of >> >> negative count

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Antoine Pitrou
On Thu, 16 Jan 2014 04:42:43 -0500 Terry Reedy wrote: > On 1/16/2014 3:31 AM, Serhiy Storchaka wrote: > > 16.01.14 08:05, Guido van Rossum написав(ла): > >> In this specific case it's clear to me that the special-casing of > >> negative count is intentional -- presumably it emulates sequence > >>

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Antoine Pitrou
On Wed, 15 Jan 2014 21:55:46 -0800 Larry Hastings wrote: > > Passing in "None" here is inconvenient as it's an integer argument. Inconvenient for whom? The callee or the caller? Regards Antoine. ___ Python-Dev mailing list Python-Dev@python.org htt

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Terry Reedy
On 1/16/2014 3:31 AM, Serhiy Storchaka wrote: 16.01.14 08:05, Guido van Rossum написав(ла): In this specific case it's clear to me that the special-casing of negative count is intentional -- presumably it emulates sequence repetition, where e.g. 'a'*-1 == ''. In this specific case it's contrar

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Serhiy Storchaka
16.01.14 08:05, Guido van Rossum написав(ла): In this specific case it's clear to me that the special-casing of negative count is intentional -- presumably it emulates sequence repetition, where e.g. 'a'*-1 == ''. In this specific case it's contrary to sequence repetition. Because repeat('a',

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-16 Thread Serhiy Storchaka
16.01.14 07:55, Larry Hastings написав(ла): * itertools.repeat deliberately makes it impossible to provide an argument for "times" that behaves the same as not providing the "times" argument, and * there is currently no way to implement this behavior using Argument Clinic. (I'd h

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-15 Thread Larry Hastings
On 01/15/2014 10:21 PM, Georg Brandl wrote: Am 16.01.2014 05:35, schrieb Ryan Smith-Roberts: On Wed, Jan 15, 2014 at 7:57 PM, Ryan Smith-Roberts mailto:r...@lab.net>> wrote: socket.getservbyname(servicename[, protocolname]) -> socket.getservbyname(servicename, protocolname=None)

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-15 Thread Georg Brandl
Am 16.01.2014 05:35, schrieb Ryan Smith-Roberts: > On Wed, Jan 15, 2014 at 7:57 PM, Ryan Smith-Roberts > wrote: > > socket.getservbyname(servicename[, protocolname]) > -> > socket.getservbyname(servicename, protocolname=None) > > > Here is a more complicated exa

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-15 Thread Guido van Rossum
On Wed, Jan 15, 2014 at 9:55 PM, Larry Hastings wrote: > > On 01/15/2014 09:37 PM, Guido van Rossum wrote: > > Well, I think these are mostly artifacts from old times, and usually passing > None *should* be the same as omitting the argument. But check each case! > > > Vajrasky Kok's recent posting

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-15 Thread Larry Hastings
On 01/15/2014 09:37 PM, Guido van Rossum wrote: Well, I think these are mostly artifacts from old times, and usually passing None *should* be the same as omitting the argument. But check each case! Vajrasky Kok's recent posting to python-dev discusses the same problem. His example is iterto

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-15 Thread Guido van Rossum
Well, I think these are mostly artifacts from old times, and usually passing None *should* be the same as omitting the argument. But check each case! On Wednesday, January 15, 2014, Larry Hastings wrote: > > On 01/15/2014 08:35 PM, Ryan Smith-Roberts wrote: > > On Wed, Jan 15, 2014 at 7:57 PM,

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-15 Thread Larry Hastings
On 01/15/2014 08:35 PM, Ryan Smith-Roberts wrote: On Wed, Jan 15, 2014 at 7:57 PM, Ryan Smith-Roberts > wrote: socket.getservbyname(servicename[, protocolname]) -> socket.getservbyname(servicename, protocolname=None) Here is a more complicated example, since t

Re: [Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-15 Thread Ryan Smith-Roberts
On Wed, Jan 15, 2014 at 7:57 PM, Ryan Smith-Roberts wrote: > socket.getservbyname(servicename[, protocolname]) > -> > socket.getservbyname(servicename, protocolname=None) > Here is a more complicated example, since the above does technically have an alternative fix: sockobj.sendmsg(buffers[, an

[Python-Dev] AC Derby and accepting None for optional positional arguments

2014-01-15 Thread Ryan Smith-Roberts
One of the downsides of converting positional-only functions to Argument Clinic is that it can result in misleading docstring signatures. Example: socket.getservbyname(servicename[, protocolname]) -> socket.getservbyname(servicename, protocolname=None) The problem with the new signature is that i