-
Notifications
You must be signed in to change notification settings - Fork 384
Description
(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. And copy.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__ as copy.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 with self", 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 on Config, not on DataProxy 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.