[Python-Dev] AC Derby and accepting None for optional positional arguments (original) (raw)

Steven D'Aprano steve at pearwood.info
Fri Jan 17 09:21:06 CET 2014


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 value: socket.getservbyname(servicename, protocolname=None) Unfortunately, while useful and inspectable, this signature is not correct. For a pure Python function, passing None for protocolname is the same as omitting it. However, if you pass None to getservbyname(), it raises a TypeError. So, we have these three options: 1) Don't give getservbyname() an inspectable signature. 2) Lie to the user about the acceptability of None. 3) Alter the semantics of getservbyname() to treat None as equivalent to omitting protocolname. Obviously #2 is out. My question: is #3 ever acceptable? It's a real change, as it breaks any code that relies on the TypeError exception.

The answer seems straightforward to me: it should be treated as any other change of behaviour, and judged on a case-by-case basis. I think the bug tracker is the right place to ask. Since it's not a bug fix, it may be able to be changed, but not lightly, and not in a bug-fix release.

The fact that the motivation for the behaviour change is Argument Clinic should not change the decision, as far as I can see. Would a feature request "Allow None as default protocolname" be accepted?

-- Steven



More information about the Python-Dev mailing list