La seguente funzione restituisce None
:Cosa sta facendo None nell'attributo co_consts dell'oggetto codice?
In [5]: def f():
...: pass
Quindi non mi ha sorpreso per questa uscita:
In [8]: dis.dis(f)
2 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
In [10]: f.__code__.co_consts
Out[10]: (None,)
Ok, questo ha un senso. Ma ora, si consideri la seguente funzione:
In [11]: def g():
....: return 1
In [12]: dis.dis(g)
2 0 LOAD_CONST 1 (1)
3 RETURN_VALUE
In [13]: g.__code__.co_consts
Out[13]: (None, 1)
g
non usa None
, quindi perché è a co_consts
?