-
-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot load class with metaclass thats using dynamic classes #253
Comments
This was from a long time ago, but it is kind of relevant. Right now, def __new__(meta, name, bases, dct):
if '_new_entered' not in dct:
# Remove params from class definition to avod inheritance
# (and hence "repetition")
newparams = dct.pop('params', ())
# Create the new class - this pulls predefined "params"
cls = super(MetaParams, meta).__new__(meta, name, bases, dct)
# Subclass and store the newly derived params class
cls.params = MetaParams._derive(name, newparams)
cls._new_entered = True
return cls
else:
return type.__new__(meta, name, bases, dct) |
@anivegesana: nice workaround -- of course people shouldn't have to write that many lines of specialized code for a workaround. It seems, however, that you could pack it into a decorator. It would be new to |
Yep. I was going to suggest that there would be a setting to turn off class initialization, but I haven't yet found time to see if this was possible. |
These are my first steps with
dill
and I am trying to pickle a calculation result of thebacktrader
framework which is a stock trading framework (https://www.backtrader.com/).Using
dill
did not work out of the box. It failed on trying to unpickle the object.backtrader
makes heavy use of metaclasses and classes that are generated at runtime so I guess it is a difficult case fordill
.From the
backtrader
framework I extracted and copy/pasted some code to build a minimal example to show the problem. It fails ondill.load(open(filename, 'rb'))
:This gives me this exception:
My interpretation of what is happening (while I am sure you are much better at understanding it as I am):
The class
LineRoot
has to be pickled. It gets instantiated by the metaclassMetaParams
. On normal run, the parameterdct
in this method:is a
dict
which contains the entryparams
which again is adict
. Based onparams
the method_derive
creates a new class which is assigned as the new value of the class variableparams
.Now when running the unpickle process then the
params
entry in thedct
already is the dynamic class that should be created later. The code does not expect it to be that and fails.In the code there are several places where this pattern is used. Is there any chance to get it working with
dill
?Big thanks in advance!
Oh this is my environment:
Python 3.6.3 :: Anaconda, Inc.
dill 0.2.7.1 py36hf552773_0
Windows 10
The text was updated successfully, but these errors were encountered: