
On Tue, Jan 26, 2016 at 10:52:59AM +1100, Chris Angelico wrote:
On Tue, Jan 26, 2016 at 10:21 AM, Steven D'Aprano <steve@pearwood.info> wrote:
- It allows us to avoid the "default argument" idiom, in cases where we really don't want the argument, we just want to capture the value. There are a lot of functions which have their parameter list polluted by extraneous arguments that should never be used by the caller simply because that's the only way to get early binding/value capturing.
Can you actually name a few, please?
The random module is the first example that comes to mind. Up until 3.3, the last argument was spelled "int" with no underscore: py> inspect.signature(random.randrange) <Signature (start, stop=None, step=1, _int=<class 'int'>)> random.shuffle also used to have an int=int argument, but it seems to be gone in 3.5.
I went digging earlier, and couldn't find any really good examples in the stdlib - they're mostly internal functions (underscore-prefixed) that shouldn't be being called from outside their own module anyway. Maybe this isn't as common an issue as I'd thought.
Obviously you can get away with more junk in a private function than a public function, but it's still unpleasant. Even if it only effects the maintainer of the library, not the users of it, a polluted signature is still polluted. -- Steve