Parens do create a tuple

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Apr 11 04:01:29 EDT 2016


On Monday 11 April 2016 15:27, Random832 wrote:

> On Mon, Apr 11, 2016, at 00:08, Steven D'Aprano wrote:
>> Should we say that the / and - operators therefore create tuples? I don't
>> think so.
> 
> But I am talking about the tuple that is passed to FunctionType.__call__
> at runtime, not a tuple created within some parser stage.


What tuple that is passed to FunctionType.__call__?

Where is the tuple in these examples?


py> from types import FunctionType
py> FunctionType.__call__(lambda x: x+1, 23)
24
py> FunctionType.__call__(lambda x, y: str(x)+str(y), 23, 42)
'2342'

I don't see any evidence of a tuple being involved anywhere visible from 
Python code. How do you know that there's a tuple involved? (That's not a 
rhetorical question, I am genuinely curious.)

In you want to tell me that, deep inside the CPython implementation, 
function calls involve an invisible and inaccessible tuple of arguments, 
then I'll say "That's interesting, but not really relevant." There could be, 
and probably are, all sorts of places in Python's implementation where 
tuples are used internally. But that's not a language feature, its an 
implementation detail.



-- 
Steve




More information about the Python-list mailing list