Message353508
CPython's Data Model -> Internal types -> Code objects, direct link as of version 3.7 is: https://docs.python.org/3.7/reference/datamodel.html?highlight=co_stacksize#index-55 , states following:
* "co_nlocals is the number of local variables used by the function (including arguments);"
* "co_stacksize is the required stack size (including local variables);"
However, practical checking shows that co_stacksize is the required stack size WITHOUT local variables. One could argue about the meaning of "local variables" in the description of co_stacksize above, saying that what is meant is temporary stack variables of something. That's why I quoted above co_nlocals description too, it clearly shows that local variebles are local function variables (include functions args), and nothing else.
Code to reproduce:
======
def func():
a = 1
b = 2
c = 3
print("co_stacksize", func.__code__.co_stacksize)
print("co_nlocals", func.__code__.co_nlocals)
======
Result of running:
======
$ python3.7 script_under_test.py
co_stacksize 1
co_nlocals 3
======
Clearly, co_stacksize doesn't include the size of local vars, or it would have been larger than co_nlocals in printout. |
|
| Date |
User |
Action |
Args |
| 2019-09-29 20:34:54 | pfalcon | set | recipients:
+ pfalcon, docs@python |
| 2019-09-29 20:34:54 | pfalcon | set | messageid: <[email protected]> |
| 2019-09-29 20:34:54 | pfalcon | link | issue38316 messages |
| 2019-09-29 20:34:53 | pfalcon | create | |
|