Ammar Askar <am...@ammaraskar.com> added the comment:

Yeah, that parenthesized bit seems a bit weird: co_stacksize really has nothing 
to do with the number of variables, it's just that certain opcodes 
(https://docs.python.org/3/library/dis.html#python-bytecode-instructions) push 
and pop off the stack, co_stacksize is just the largest the stack will ever 
grow to from these operations.

For example:

  >>> def f():
  ...   a = 1
  ...   b = 2
  ...   c = 3
  ...   g(a, b, c)
  ...
  >>> f.__code__.co_stacksize
  4

and

  >>> def g():
  ...   g(1, 2, 3)
  ...
  >>> g.__code__.co_stacksize
  4

have the exact same stack size despite differences in variables because the 
call to `g` has to push all 3 operands (and g itself) onto the stack.

----------
nosy: +ammar2

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38316>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to