python - isinstance() returns false when the fully-qualified object class differs from the qualified class -
when 3rd party library method uses isinstance()
compare object class, returns false
because compares qualified class name of object qualified class name starts "higher" up.
e.g.: isinstance()
finds object class , classname differ:
expected:
'network.mhistory.service.mhistory_messages.mhistoryactivityviewmessage'
found:
'backend.network.mhistory.service.mhistory_messages.mhistoryactivityviewmessage'
and returns false
given code snippet:
if not isinstance(value, self.type): raise validationerror('expected type %s field %s, ' 'found %s (type %s)' % (self.type, name, value, type(value)))
is there way change qualified name of class (at least temporarily)?
as far python concerned, classes network.mhistory.service.mhistory_messages.mhistoryactivityviewmessage
, backend.network.mhistory.service.mhistory_messages.mhistoryactivityviewmessage
not same. that's true if have same definition because read same file!
your bug isn't isinstance
returning "wrong" answer, it's you're able access 2 classes (and possibly others well) 2 different names.
there 2 different problems leading bug. first, you've got code somewhere messing around sys.path
. isn't inherently bad, it's causing problems making contents of backend
package available 2 differnet ways, first directly (e.g. import network
) , via backend
(from backend import network
). don't want this.
the second part of bug (which may have been motivating factor leading first part), you're using both ways of accessing objects. need one, , should fix parts import package wrong way.
Comments
Post a Comment