-
Notifications
You must be signed in to change notification settings - Fork 206
Fix multiple associations and removals of networks #573
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
Fix multiple associations and removals of networks #573
Conversation
2436923
to
7e82e28
Compare
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.
Nice. Mainly nit-picks, and I do welcome to use the existing .has_network()
method. I don't quite think automatically re-associating to a different network is appropriate. Associating twice without removing from the first network will more likely point toward a programming error rather than a conscious, common workflow.
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
canopen/network.py
Outdated
# Remove empty list entry | ||
if not self.subscribers[can_id]: | ||
del self.subscribers[can_id] |
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.
I meant something like this instead, with a single del
code-path. I find that easier to reason about:
if callback is not None:
self.subscribers[can_id].remove(callback)
if not self.subscribers[can_id] or callback is None:
del self.subscribers[can_id]
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.
Yes, two lines shorter.
test/test_node.py
Outdated
import canopen.network | ||
import canopen.objectdictionary |
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.
These seem to be not needed.
import canopen.network | |
import canopen.objectdictionary |
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.
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.
I understand. How come the code works without them though?
test/test_node.py
Outdated
@@ -0,0 +1,113 @@ | |||
"""Unit tests for the RemoteNode and LocalNode classes.""" |
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.
I'm not really fond of having comments just for the sake of having a comment. None of our test files so far have a module-level docstring. There is no generated API documentation for them. And import unittest
says just as much as this comment, while the enumeration of classes is redundant and bound to get out of sync sometime.
In essence, don't feel obliged to write docstrings that add no value. Or try to come up with a really good one that does so.
What IS the common denominator for stuff that will be grouped in this test file? So far it is only network association, what else do you have in mind?
"""Unit tests for the RemoteNode and LocalNode classes.""" |
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.
What IS the common denominator for stuff that will be grouped in this test file? So far it is only network association, what else do you have in mind?
Eventually we'll have more unit tests of the methods in these two classes, no?
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.
Maybe, that's why I'm asking if you have any concrete ideas what will be added?
I took the liberty to apply my suggested changes. Should be uncontroversial I hope. Please indicate whether you are happy with the last commit's logic "simplification", it might seem simpler only to me :-) |
Comments updated. No objections. You and I have very different coding styles my friend 😎 While in many projects the commit is rejected for not having docstrings, here its removed because its not informative enough 🎉 It's fine, I just find it amusing. One certainly needs to learn every project's individual styles, that's for sure. Even the undocumented ones :D PS! I don't know, but I don't have push authorization no more since the project move. Was that deliberate? |
Yes, I know my stance on coding style is not average. And I'm happy that you're open to adjusting. It's mostly stuff where my experience tells me that exceptions from any rule might be better than following it blindly. There should always be room for well-reasoned deviation. To the question at hand: I really hate comments stating the obvious that give no further information than what the (well-written) code already tells. It's just twice the reading effort, and only makes sense if the docstrings are needed for auto-generated docs. This is different in the context of unit tests, not the actual library classes. And if we wanted to be perfect, there would be many many test functions with "Missing docstring in public method" messages to tackle.
Not that I know of. The move was done by Christian, I haven't adjusted any permissions since. What exactly can you no longer do? Actually, I did change one thing: Activate branch protections for the |
Hope it works now. My intention was to disallow direct pushes, but merging pull requests should still be allowed for people with write access (which you do have). I disabled the "Restrict who can push to matching branches" setting again, hope that has the desired effect. |
I have access now. Thanks! Since we're into discussions about merging: What is your preferred approach to merge? Is squash and merge the way to go? -- I personally tend to prefer that with public PRs, since there often will be a bit back and forth, like this one, where there will be many minor tweak commits. |
Yes, squash and merge should do it. Unless we have special circumstances with a perfectly hand-crafted commit history. Which is pretty rare. |
Merged! Thank you for the review @acolomb |
Great! Thank you very much for your continued involvement and you patience with reviews :-) |
One more thing about the removed imports, forgot to write it down: The The same doesn't apply to the As long as the tests work, I don't mind much about it though. It's only unit test code 😉 |
This PR fixes the issue of not being able to call
associate_network()
andremove_network()
multiple times. See #562.Fixes #562