Author pfalcon
Recipients docs@python, pfalcon
Date 2019-09-29.20:34:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
CPython's Data Model -> Internal types -> Code objects, direct link as of version 3.7 is: , 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 
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:54pfalconsetrecipients: + pfalcon, docs@python
2019-09-29 20:34:54pfalconsetmessageid: <>
2019-09-29 20:34:54pfalconlinkissue38316 messages
2019-09-29 20:34:53pfalconcreate