Skip to content
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

[WIP] introduction of Arbitration_id class #296

Merged
merged 7 commits into from
Feb 26, 2019
Merged

[WIP] introduction of Arbitration_id class #296

merged 7 commits into from
Feb 26, 2019

Conversation

ebroecker
Copy link
Owner

should fix #144

@codecov-io
Copy link

codecov-io commented Feb 24, 2019

Codecov Report

Merging #296 into development will increase coverage by 0.35%.
The diff coverage is 43.64%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #296      +/-   ##
===============================================
+ Coverage        37.81%   38.16%   +0.35%     
===============================================
  Files               34       34              
  Lines             6820     6841      +21     
  Branches          1675     1669       -6     
===============================================
+ Hits              2579     2611      +32     
+ Misses            4023     4016       -7     
+ Partials           218      214       -4
Impacted Files Coverage Δ
src/canmatrix/xls_common.py 3.33% <0%> (ø) ⬆️
src/canmatrix/fibex.py 10.84% <0%> (ø) ⬆️
src/canmatrix/convert.py 6.01% <0%> (ø) ⬆️
src/canmatrix/xlsx.py 1.05% <0%> (ø) ⬆️
src/canmatrix/dbf.py 4.2% <0%> (-0.02%) ⬇️
src/canmatrix/arxml.py 11.37% <0%> (ø) ⬆️
src/canmatrix/kcd.py 5.05% <0%> (ø) ⬆️
src/canmatrix/xls.py 10.55% <0%> (-0.03%) ⬇️
src/canmatrix/cmcsv.py 14.68% <0%> (ø) ⬆️
src/canmatrix/tests/test_frame_encoding.py 100% <100%> (ø) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69a7832...1b22bda. Read the comment docs.

@ebroecker
Copy link
Owner Author

@altendky
could you have a look on the arbitration_id class?

It's not necessary to look on every single source line which had to be changed...

Copy link
Collaborator

@altendky altendky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't check to see how exactly this compared with what I had before so for all I know my suggestions are really just correcting myself... If it would be easier I can just make a PR against this to show what I have in mind. That would force me to work through any conflicts that arise from my suggestions. :]

src/canmatrix/canmatrix.py Outdated Show resolved Hide resolved
compound_extended_mask = (1 << 31)

id = attr.ib(default=None)
extended = attr.ib(default=None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extended = attr.ib(default=None)
extended = attr.ib(default=True)

extended = attr.ib(default=None)

def __attrs_post_init__(self):
if self.extended is None or self.extended:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.extended is None or self.extended:
if self.extended:

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was the requirement to get both arbitration ids - the extended and the basic one - with the "by_id" method. Therefore the "None" was. If you set extended to "None" and compare two arbitration ids you'll get a true for both - the extended and the basic version.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... maybe by_id() should be return itertools.chain.from_iterable(by_id(id, extended) for type in (False, True)) or less niftily return by_id(id, False) + by_id(id, True). (aside from the recursion in both cases...). I'm really not sure. I'm just taking to simpler classes at this point. :| Do what you want and we'll see how we feel about it later.

else:
return self.id

def __eq__(self, other):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be able to drop this after the above changes? The default attrs-provided __eq__ should work and if it doesn't we should probably try to look for a way to make it.

id = attr.ib(default=None)
extended = attr.ib(default=None)

def __attrs_post_init__(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tending away from writing __attrs_post_init__s anymore. I think this could be just a helper @classmethod that the from_compound_integer() calls. We should be able to construct any class we want rather than having to create it and then modify to get to any arbitrary set of attributes.

raise ArbitrationIdOutOfRange('ID out of range')

@classmethod
def from_compound_integer(cls, i):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def from_compound_integer(cls, i):
def from_compound_integer(cls, i, extended=True):

And associated changes inside the function.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... the compound_integer already has the extendedinformation in bit 31 - so no need for the extended attribute. Or do I miss something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:[ oh right, it's compound... I'm really not on my game today, sorry.

@@ -574,10 +617,10 @@ class Frame(object):
"""

name = attr.ib(default="")
id = attr.ib(type=int, default=0)
arbitration_id = attr.ib(converter=Arbitration_Id.from_compound_integer, default=0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to be so verbose re: arbitration_id over id? It might be better, but I'm not sure there's likely much confusion with just id. Either way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention, id is a python keyword. It would lead to "shadowing" warning.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it presumably has been already. I can't say I like it but it only shadows in the class definition itself. Once you are outside the class definition there's no more shadowing since it's self.id. Since you mostly shouldn't use id() at all anyways... I think I'm ok with this. It's a hazard of mixing declarative with imperative like attrs does in this style usage.

size = attr.ib(default=0)
transmitters = attr.ib(type=list, factory=list)
extended = attr.ib(type=bool, default=False)
# extended = attr.ib(type=bool, default=False)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, So we're changing from default=False to default=True effectively above. I'm not sure which it should be, or how much it matters.

Do delete this before it gets left hanging around.

@ebroecker
Copy link
Owner Author

OK, I'll merge - we can work on it later again...

@ebroecker ebroecker merged commit cf8e53e into development Feb 26, 2019
@ebroecker ebroecker deleted the iss144 branch February 26, 2019 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

handling of extended CAN id
4 participants