From: eap Date: Wed, 5 Feb 2014 08:08:10 +0000 (+0000) Subject: 22465: [CEA] sometimes isinstance(m, Mesh) returns False for Mesh objects // PPGP pb X-Git-Tag: V7_4_0a1~85 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fce720f2d2f461f2812cc618cb7655eb26f7a993;p=modules%2Fsmesh.git 22465: [CEA] sometimes isinstance(m, Mesh) returns False for Mesh objects // PPGP pb class MeshMeta(type): def __instancecheck__(cls, inst): """Implement isinstance(inst, cls).""" return any(cls.__subclasscheck__(c) for c in {type(inst), inst.__class__}) def __subclasscheck__(cls, sub): """Implement issubclass(sub, cls).""" return type.__subclasscheck__(cls, sub) or (cls.__name__ == sub.__name__ and cls.__module__ == sub.__module__) ... class Mesh: __metaclass__ = MeshMeta ... --- diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index 779aeb24e..5af2bea9b 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -93,6 +93,16 @@ import SALOME import SALOMEDS import os +class MeshMeta(type): + def __instancecheck__(cls, inst): + """Implement isinstance(inst, cls).""" + return any(cls.__subclasscheck__(c) + for c in {type(inst), inst.__class__}) + + def __subclasscheck__(cls, sub): + """Implement issubclass(sub, cls).""" + return type.__subclasscheck__(cls, sub) or (cls.__name__ == sub.__name__ and cls.__module__ == sub.__module__) + ## @addtogroup l1_auxiliary ## @{ @@ -1144,6 +1154,7 @@ def New( study, instance=None): # new nodes and elements and by changing the existing entities), to get information # about a mesh and to export a mesh into different formats. class Mesh: + __metaclass__ = MeshMeta geom = 0 mesh = 0 @@ -4596,7 +4607,7 @@ class Mesh: return self._valueFromFunctor(SMESH.FT_Skew, elemId) pass # end of Mesh class - + ## Helper class for wrapping of SMESH.SMESH_Pattern CORBA class # class Pattern(SMESH._objref_SMESH_Pattern):