Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to get isinstance or similar type-checking to work with my pickled classes?
    primarykey
    data
    text
    <p>I have a really annoying bug, and I've finally tracked it down. </p> <p>I use (or more accurately, already have used) a stand-alone script to create a store of objects, after which I pickle this data structure. I can then initialize my main program with the deserialized data each time my program runs.</p> <p>This becomes a problem, however, if I use type-checking. After I do pickle.dump() and get this data structure, I had it set up so that I try to check the type of one the objects. Unfortunately, the only thing I can check it against is a <em>new</em> reloading of my classes, which Python recognizes as distinct.</p> <blockquote> <p>DEBUG: Object I am type-checking: >> Fixture {name: 'Front Desk', location: '0', desc: 'The front desk has a sign that read...'} &lt;&lt;<br> DEBUG: A generic GameObject: >> GameObject {name: '', location: 'None', desc: '...' } &lt;&lt; </p> </blockquote> <p>(You can see that the object representations look very similar. This is because the one inherits its <code>__repr__</code> from the other, i.e. OUGHT to be an instance of it.)</p> <blockquote> <p>DEBUG: Type of object I am type-checking: {class 'chimai.chimai.objects.fix.Fixture'}<br> DEBUG: Type of generic GameObject: {class 'objects.game_object.GameObject'}<br> DEBUG: MRO for the object I'm type-checking: ({class 'chimai.chimai.objects.fix.Fixture'}, {class 'chimai.chimai.objects.game_object.GameObject'}, {type 'object'})<br> DEBUG: MRO for the generic GameObject: ({class 'objects.game_object.GameObject'}, {type 'object'}) </p> </blockquote> <p>(The GameObject classes have slightly different identifiers; this comes from where I ran the standalone script originally.)</p> <blockquote> <p>DEBUG: Id of pickled Fixture type: 173671604<br> DEBUG: Id of Fixture type as reloaded in my main program: 149507748 </p> </blockquote> <p>The end result is, I can't think of a way to type-check my pickled data at all. Unless anyone has any genius proposals, I think I'll be duck-typing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload