-
Notifications
You must be signed in to change notification settings - Fork 407
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
T196 fix additional frame #197
T196 fix additional frame #197
Conversation
Codecov Report
@@ Coverage Diff @@
## development #197 +/- ##
==============================================
+ Coverage 10.16% 10.2% +0.03%
==============================================
Files 24 24
Lines 5694 5674 -20
Branches 1591 1596 +5
==============================================
Hits 579 579
+ Misses 5069 5049 -20
Partials 46 46
Continue to review full report at Codecov.
|
Yeah, getattr(signal, item, signal.attributes.get(item, "")) Or just add a getter. NOTHING = object()
def get(self, item, default=NOTHING):
item = getattr(self, item, self.attributes.get(item, default))
if item is NOTHING:
raise SomeException()
return item signal.get(item, "") |
Totally agree, your solution is better. I'll apply it. There is still question if it make sense to have some "additional attributes" as instance variables and some in the attributes dictionary. It would make sense to have them all on a single place. But I didn't want to touch the existing code, because... I'm just a passerby. |
If I remember a conversation with @ebroecker correctly, it would be nice to revisit these 'attributes' and try to figure out which are common and how to nestle the rest together happily. Basically, there is a dbc bias and with the extra knowledge of other formats we could probably do a better job picking regular attributes to have. Thanks for seeing the mess and doing something about at least part of it. :] We appreciate the help. |
@Funth0mas |
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.
Thanks for the follow up. I won't make a fuss about pulling this apart but keep in mind for the future that this would be easier to review as three separate PR's. The original, the formatting, and the comments. I prefer the modified formatting but I'll leave it to @ebroecker to decide. Cheers.
src/canmatrix/canmatrix.py
Outdated
:param default: Default value if attribute doesn't exist. | ||
:return any: Return the attribute value if found, else `default` or None | ||
""" | ||
if hasattr(self, name): |
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.
Sorry to evolve my request here... I forgot this was an attrs
class and I think this will be a touch better. It will avoid considering methods and such as attributes.
https://www.attrs.org/en/stable/api.html#attr.fields_dict
if name in attr.fields_dict(type(self)):
I'll note that this is technically a breaking change given the it will block access via this method to .attribute
items that shadow the names of regular attributes. But, I don't think that bothers me.
src/canmatrix/cmjson.py
Outdated
@@ -101,21 +101,21 @@ def dump(db, f, **options): | |||
"signals": signals} | |||
frame_attributes = {} | |||
for frame_info in additionalFrameColums: # Look for additional Frame Attributes | |||
if hasattr(frame, frame_info): | |||
frame_attributes[frame_info] = getattr(frame, frame_info) | |||
if frame.attribute(frame_info): # does the attribute exist? |
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 doesn't check it's existence. If it exists but is None
or anything else falsey it will be treated as not present. Here's the first thing that came to my mind, though it is a touch smelly to me. Maybe you can think of something nicer.
MISSING = object()
value = frame.attribute(name=frame_info, default=MISSING)
if value is not MISSING:
frame_attributes[frame_info] = value
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.
good point! As there is imho no reason to export None value, change to is not None
I ran the autoformating on the whole file by accident. If it's problem, I'll revert it line per line. Sorry for the inconvenience. |
No big deal, I just tend to mention more rather than less. Thanks for the help improving the code. |
Ready for review again. Thanks! |
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.
Thank you for improving the code.
I'll accept it as is. The only change is the comment about "is_multiplexed" - maybe you could correct..
Thanks
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.
Alrighty, so fix up the is_multiplex
comment and the .detach()
and I think it'll get merged. Thanks again for your patience and effort.
The failed appveyor isn't my fault :-( |
Agreed, we'll keep an eye on it and see if it was a temporary issue or not. (pypy3 is just broken, but yeah, pypy2 was working) |
768fecf
to
ac25589
Compare
ac25589
to
f7d6336
Compare
@Funth0mas are you referring to 3bdafa9? I generally do a Anyways, if this looks right to you I'm ready to merge. |
@altendky funny thing is that I did almost the same except of using more complicated |
Thanks for all the code and your responsiveness. Cheers, |
My pleasure. BTW you're from Germany? |
No, only I am from Germany, altendkey Not... |
Extend
--additionalFrameAttributes
to support any attribute name. Add this feature to json export. Replaceeval()
bygetattr()
.