-
Notifications
You must be signed in to change notification settings - Fork 371
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
copy.copy() isn't happy with DataProxy under Python 3 #426
Comments
Yea, seems like we could:
Figure the former is gonna be simpler as it's basically |
Yea, a simple def __copy__(self):
new = self.__class__()
new._config = copy.copy(self._config)
return new However, I anticipate that things will get clunky in the corner cases - e.g. this totally skips around This is also a confusing spot because May make more sense to require the 'concrete' subclasses of Arguably, though, it'd be better to leverage |
Yup, in fact even under Python 2 we get our friendly RecursionErrors just trying to |
Keep going in circles though; the core problem is that all attempts to unpickle or copy at some point must be able to ask our objects if they have a Wonder if I'm overlooking a really stupid simple solution like "if somebody is literally asking for our |
Yea...that works fine and the result seems to be healthily copied. Will consider expanding on this for replacing |
(Note: this is notes-to-self; it's predicated partly on some deeper changes to
Config
that I haven't merged to master just yet, though I plan to soon.)Discovered this when implementing configuration support for Fabric 2 ProxyJump style gateways (i.e. connection objects, which inherit from invoke's Context, being stored in other connection objects' configuration - which then get
copy
'd when the config re-merges).Not 100% sure why (I probably knew at some point) but under Python 3 only,
hasattr(<newly created but not __init__'d Context>, 'anything')
RecursionErrors, while Python 2 happily continues. Andcopy.copy
at one point on both interpreters checks for__setstate__
(as it uses that part of the pickle protocol.)Unfortunately it's not as simple as defining a dummy
__setstate__
ascopy.py
doesn't do any checking besides "do you exist? ok I'm calling you" and so if we define it we must define (AFAICT) the entire pickling suite, or at least__getstate__
too.I quickly poked at my usual workaround of "call the
object
method withself
", hoping to tell our usual kit "hey if you don't even have_config
yet, treat that as a miss" but that doesn't fly with__getattribute__
for reasons.Feels like the Right Thing is to, you know. Actually implement an explicit "this is what I means to copy a Context/DataProxy type of object" set of methods.
I was hoping I could just pass through to
.clone
but...that's only onConfig
, not onDataProxy
itself. So now I have to figure out if it's sensible to split up.clone
(and/or restate it in terms of the pickling methods) between the two classes, or what.The text was updated successfully, but these errors were encountered: