Skip to content

Commit

Permalink
Preserve .java reference when type-casting to child class.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-hen committed Feb 24, 2021
1 parent 07c2444 commit eb42e23
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions mph/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,21 @@ class is not intended to be instantiated directly. Rather, the
Though if you wish to do that, just use the instance attribute
`.java` to access the entire Comsol Java API from Python and refer
to the Comsol Programming Manual for guidance.
The `parent` argument to the constructor is usually that internal
Java object around which this class here is wrapped. But in order
to simplify extending the class with custom functionality, the
constructor also accepts instances of this class or a child class.
In that case, it will preserve the original `.java` object throughout
the class hierarchy so that you can simply "type-cast" an existing
`Model` instance (as loaded by the client) to a derived child class.
"""

def __init__(self, java):
self.java = java
def __init__(self, parent):
if isinstance(parent, Model):
self.java = parent.java
else:
self.java = parent

def __eq__(self, other):
return self.java.tag() == other.java.tag()
Expand Down

0 comments on commit eb42e23

Please sign in to comment.