Closed vstinner closed 2 years ago
While you're waiting for official docs, here's the new constructor: https://github.com/python/cpython/blob/18f41c04ff4161531f4d08631059fd3ed37c0218/Lib/test/test_code.py#L216-L232
@vstinner Would you mind testing this again? In a23f3054b96b487215b04812c680075c5117470a I changed the code so we don't use the constructor anymore and maybe that also fixed the 3.11 problem. (Fedora has now 3.11 package yet so testing this is a bit more complicated for me.)
@FelixSchwarz: I still get test errors, in another function:
======================================================================
ERROR: test_pickle (genshi.template.tests.eval.ExpressionTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vstinner/dev/genshi/genshi/template/tests/eval.py", line 45, in test_pickle
unpickled = pickle.load(buf)
^^^^^^^^^^^^^^^^
File "/home/vstinner/dev/genshi/genshi/template/eval.py", line 92, in __setstate__
self.code = CodeType(0, *state['code'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: code expected at least 18 arguments, got 16
======================================================================
ERROR: test_pickle (genshi.template.tests.eval.SuiteTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vstinner/dev/genshi/genshi/template/tests/eval.py", line 551, in test_pickle
unpickled = pickle.load(buf)
^^^^^^^^^^^^^^^^
File "/home/vstinner/dev/genshi/genshi/template/eval.py", line 92, in __setstate__
self.code = CodeType(0, *state['code'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: code expected at least 18 arguments, got 16
======================================================================
ERROR: test_pickle (genshi.template.tests.markup.MarkupTemplateTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vstinner/dev/genshi/genshi/template/tests/markup.py", line 52, in test_pickle
unpickled = pickle.load(buf)
^^^^^^^^^^^^^^^^
File "/home/vstinner/dev/genshi/genshi/template/eval.py", line 92, in __setstate__
self.code = CodeType(0, *state['code'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: code expected at least 18 arguments, got 16
Commands:
$ ~/python/main/python -m venv env # Python 3.11 (dev)
$ env/bin/python setup.py test
Maybe Code.__setstate__()
should recompile the code using self.code = _compile(...)
rather than serializing CodeType parameters.
To build Python 3.11:
git clone https://github.com/python/cpython/
cd cpython
./configure
make
No need to install it: just use the ./python
build in the root directory of the source code.
Ah, that is the part I left open in #49 but @hodgestar is currently working on some fixes as part of #50 (for Python 3.10). Yeah, guess I'll have to set up a Python 3.11 then (though free time is pretty limited - as always :-).
Thank you for re-testing this.
Since I was doing this for my own templating engine Tonnikala and was just casually browsing around, I noticed that Genshi seems to have accidentally swapped co_kwonlyargcount
and co_nlocals
c.f. CPython help() for code objects...
@ztane thank you for reporting this. I filed #52 so this won't get lost.
@vstinner Thank you for your comment how to build Python 3.11 locally. It worked and I created PR #54 as a first step to make Genshi compatible with Python 3.11.
You cannot use CodeType.replace() to avoid being broken each time CodeType constructor is changed?
@vstinner We do use CodeType.replace
for Python 3.8 in build_code_chunk
, but get_code_params
is used to pickle and unpickle the code object, so I don't know if CodeType.replace
can help in that case.
Ah right, pickling code objects is non-trivial.
@vstinner Do you think CPython would be interested in support for serializing or pickling code objects? That would mean that perhaps one day this continual dance of fixing this code could end.
Hm, could you marshal
the code object instead, and use those bytes to "unmarshal" later? Not sure if that would be appropriate for your use-case.
Do you think CPython would be interested in support for serializing or pickling code objects?
I don't know. You can propose the idea on python-dev or python-ideas.
Example of error when running tests: