[issue43228] Regression in function builtins

2021-03-17 Thread STINNER Victor
STINNER Victor added the comment: Issue fixed in bpo-42990. -- priority: release blocker -> resolution: -> fixed stage: -> resolved status: open -> closed ___ Python tracker __

[issue43228] Regression in function builtins

2021-02-19 Thread Dong-hee Na
Change by Dong-hee Na : -- nosy: +corona10 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pytho

[issue43228] Regression in function builtins

2021-02-18 Thread STINNER Victor
STINNER Victor added the comment: I proposed PR 24564: "bpo-42990: Functions inherit current builtins" which should also to fix cloudpickle. -- ___ Python tracker ___ ___

[issue43228] Regression in function builtins

2021-02-18 Thread STINNER Victor
STINNER Victor added the comment: > but __builtins__.__dict__ cannot be pickled. I don't see why cloudpickle calls LambdaType() directly. It could use a helper in their cloudpickle.cloudpickle_fast which calls LambdaType() with the proper arguments, especially to get __builtins__. I don't th

[issue43228] Regression in function builtins

2021-02-18 Thread Mark Shannon
Mark Shannon added the comment: I don't think PR 24559 will be sufficient to fix this. Pickled functions need to share the builtins dict, not just have a copy of it. Adding a "builtins" parameter to types.FunctionType() should be be enough. So: function(code, globals, name=None, argdefs=Non

[issue43228] Regression in function builtins

2021-02-17 Thread STINNER Victor
STINNER Victor added the comment: I wrote PR 24559 to expose the functions builtins in Python as a new __builtins__ attributes on functions, but also to document the subtle behavior change. -- ___ Python tracker

[issue43228] Regression in function builtins

2021-02-17 Thread STINNER Victor
STINNER Victor added the comment: I wrote _testinernalcapi.get_builtins() function to help me debuging this issue: diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index ab6c5965d1..250ecc61ab 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -

[issue43228] Regression in function builtins

2021-02-17 Thread STINNER Victor
STINNER Victor added the comment: Attached func_builtins2.py mimicks the cloudpicke bug: --- def func(s): return len(s) code = func.__code__ FuncType = type(func) func2_globals = {} func2 = FuncType(code, func2_globals) # func2.func_builtins = {'None': None} func2.__globals__['__builtins__']

[issue43228] Regression in function builtins

2021-02-17 Thread STINNER Victor
STINNER Victor added the comment: In short, cloudpickle recreates a function in two steps: * Create a function object: globals doesn't contain "__builtins__" key * Update the function attributes (especially __globals__) with cloudpickle.cloudpicke_fast._function_setstate() which always sets

[issue43228] Regression in function builtins

2021-02-15 Thread Lumír Balhar
Lumír Balhar added the comment: I'm not an expert nor an author but this might help: Cloudpickle offers extended possibilities for pickling but uses the standard pickle module for unpickling: >>> import pickle, cloudpickle >>> cloudpickle.load is pickle.load True >>> cloudpickle.loads is pick

[issue43228] Regression in function builtins

2021-02-15 Thread Mark Shannon
Mark Shannon added the comment: You need to define __builtins__ in the globals dictionary. def func(s): return len(s) text = "abc" print(func(text)) FuncType = type(func) func_globals = {"__builtins__":__builtins__.__dict__} code = func.__code__ func2 = FuncType(code, func_globals) prin

[issue43228] Regression in function builtins

2021-02-15 Thread STINNER Victor
STINNER Victor added the comment: func_builtins.py: reproducer which has no import. func2 builtins is {'None': None} on Python 3.10. Oh. This script also fails on Python 3.9. I'm not sure why cloudpickle_bug.py works on Python 3.9. -- Added file: https://bugs.python.org/file49811/f

[issue43228] Regression in function builtins

2021-02-15 Thread STINNER Victor
STINNER Victor added the comment: > How is cloudpickle supposed to work? It creates a CodeType object and then create a function with this code object. It serializes the bytecode. pickle is not affected since it doesn't create function objects, but retrieve them from imported modules. ---

[issue43228] Regression in function builtins

2021-02-15 Thread STINNER Victor
STINNER Victor added the comment: > It looks like the globals dict passed to FunctionType(...) lacks a > __builtins__. Right. But it worked in Python 3.9 :-) -- ___ Python tracker _

[issue43228] Regression in function builtins

2021-02-15 Thread Mark Shannon
Mark Shannon added the comment: Do you have a reproducer that does not use cloudpickle? Pickling functions seems to work correctly. >>> import pickle >>> def func(): ... return len([]) ... >>> func2 = pickle.loads(pickle.dumps(func)) >>> >>> func2() 0 How is cloudpickle supposed to wor

[issue43228] Regression in function builtins

2021-02-15 Thread STINNER Victor
STINNER Victor added the comment: Pablo asked me to put the priority to release blocker. -- priority: normal -> release blocker ___ Python tracker ___

[issue43228] Regression in function builtins

2021-02-15 Thread STINNER Victor
Change by STINNER Victor : -- nosy: +pablogsal ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.p

[issue43228] Regression in function builtins

2021-02-15 Thread STINNER Victor
STINNER Victor added the comment: I created a new "3.10regression" for this issue ;-) -- keywords: +3.10regression ___ Python tracker ___ _

[issue43228] Regression in function builtins

2021-02-15 Thread Lumír Balhar
Change by Lumír Balhar : -- nosy: +frenzy ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.

[issue43228] Regression in function builtins

2021-02-15 Thread STINNER Victor
STINNER Victor added the comment: cloudpickle issue: https://github.com/cloudpipe/cloudpickle/issues/410 -- ___ Python tracker ___

[issue43228] Regression in function builtins

2021-02-15 Thread STINNER Victor
New submission from STINNER Victor : The bpo-42990 introduced a regression with the following commit: commit d6c33fbd346765c6a8654dccacb2338006bf2b47 Author: Mark Shannon Date: Fri Jan 29 13:24:55 2021 + bpo-42990: Introduce 'frame constructor' struct to simplify API for PyEval_Cod