-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements a different approach for __repr__ #78
Changes from 1 commit
4f335ed
5d8a033
eb98987
b482bef
019abe4
73f1aef
8da17d3
70857de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -2674,20 +2674,27 @@ def __str__(self): | |||
return str(self.read()) | ||||
|
||||
def __repr__(self): | ||||
try: | ||||
# Delegate the value reading to __str__ | ||||
read_result = str(self) | ||||
valid = True | ||||
except: | ||||
valid = False | ||||
|
||||
cls_name = '{}.{}'.format(__name__, self.__class__.__name__) | ||||
if self._mplug.attribute().apiType() == om.MFn.kCompoundAttribute: | ||||
return '{}("{}", "{}")'.format(cls_name, | ||||
self.node().name(), | ||||
self.name()) | ||||
read_val = self.read() | ||||
if isinstance(read_val, string_types): | ||||
# Add surrounding single quotes, indicating the value is a string | ||||
read_val = '"{}"'.format(read_val) | ||||
|
||||
return '{}("{}", "{}") == {}'.format(cls_name, | ||||
self.node().name(), | ||||
self.name(), | ||||
read_val) | ||||
msg = '{}("{}", "{}")'.format(cls_name, | ||||
self.node().name(), | ||||
self.name()) | ||||
if valid: | ||||
try: | ||||
if self.typeClass() == String: | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we've established that typeClass isn't relevant for all types, like kByte, how about we use Maya's apiType here instead? Especially since we're only dealing with a single type.
It would save on the use of try/except too. Did we also have a test for this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought of doing it that way as well, but thought it looked less elegant. But sounds good, let me implement that.
We do not, let me add it in. On another note:
If this is not the case anymore, and we never expect This might be getting a little too much into >>> myNode["myCompoundAttr"]
cmdx.Plug("myNode", myCompoundAttr") == Compound A third option, albeit more complex, could be to have it return a dictionary, with the child attribute names as keys for instance. >>> myNode["myCompoundAttr"]
cmdx.Plug("myNode", myCompoundAttr") == {"childA": 1.0, "childB": "Some string value.", "childC": None} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure, let's try it.
I mean, this would be supremely useful. But I'm uncertain how stable we can make this.. Maybe let's start small, and add this later on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Scratch that. We can't return something that isn't a string type from I think I was able to think of a decent solution within |
||||
# Add surrounding quotes, indicating it is a string | ||||
read_result = '"{}"'.format(read_result) | ||||
except TypeError: | ||||
pass | ||||
msg += ' == {}'.format(read_result) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to add this in order to avoid cases where it shows a valid value, but of an empty string: >>> myNode["myStr"]
cmdx.Plug("myNode", "myStr") == |
||||
|
||||
return msg | ||||
|
||||
def __rshift__(self, other): | ||||
"""Support connecting attributes via A >> B""" | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm, now str() is a call I would never expect to fail, and if it does then I'd consider that a bug. We can expect it will never fail, and not bother with a
valid = True
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the reason why I added a try/except. running the following causes an API failure:
Might be an edge case, but that was the reason why I added tat in.
I did some digging and it could be because the attribute which it fails on (
blendshape1.inputTarget[0].inputTargetGroup[0].targetBindMatrix
) has its value being cached. It is just a theory at this point though, I haven't properly diagnosed this.We could remove the try/except and deal with this as a separate issue though, which is probably a cleaner strategy.