Repository navigation
Python Warnings and PEP8: unused vars, var naming, typing, spelling etc #456
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
Closed
friederschueler
wants to merge
1
commit into
canopen-python:master
from
friederschueler:typing-unused-and-other-fixes
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ target/ | |
|
|
||
| # IDEs | ||
| .vscode/ | ||
| .idea/ | ||
|
|
||
| *.dbc | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import logging | ||
| import time | ||
| import struct | ||
| import queue | ||
| import struct | ||
| import time | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -104,21 +104,20 @@ def send_switch_mode_global(self, mode): | |
| """obsolete""" | ||
| self.send_switch_state_global(mode) | ||
|
|
||
| def send_switch_state_selective(self, | ||
| vendorId, productCode, revisionNumber, serialNumber): | ||
| def send_switch_state_selective(self, vendor_id, product_code, revision_number, serial_number): | ||
| """switch mode from WAITING_STATE to CONFIGURATION_STATE | ||
| only if 128bits LSS address matches with the arguments. | ||
| It sends 4 messages for each argument. | ||
| Then wait the response from the slave. | ||
| There will be no response if there is no matching slave | ||
|
|
||
| :param int vendorId: | ||
| :param int vendor_id: | ||
| object index 0x1018 subindex 1 | ||
| :param int productCode: | ||
| :param int product_code: | ||
| object index 0x1018 subindex 2 | ||
| :param int revisionNumber: | ||
| :param int revision_number: | ||
| object index 0x1018 subindex 3 | ||
| :param int serialNumber: | ||
| :param int serial_number: | ||
| object index 0x1018 subindex 4 | ||
|
|
||
| :return: | ||
|
|
@@ -127,10 +126,10 @@ def send_switch_state_selective(self, | |
| :rtype: bool | ||
| """ | ||
|
|
||
| self.__send_lss_address(CS_SWITCH_STATE_SELECTIVE_VENDOR_ID, vendorId) | ||
| self.__send_lss_address(CS_SWITCH_STATE_SELECTIVE_PRODUCT_CODE, productCode) | ||
| self.__send_lss_address(CS_SWITCH_STATE_SELECTIVE_REVISION_NUMBER, revisionNumber) | ||
| response = self.__send_lss_address(CS_SWITCH_STATE_SELECTIVE_SERIAL_NUMBER, serialNumber) | ||
| self.__send_lss_address(CS_SWITCH_STATE_SELECTIVE_VENDOR_ID, vendor_id) | ||
| self.__send_lss_address(CS_SWITCH_STATE_SELECTIVE_PRODUCT_CODE, product_code) | ||
| self.__send_lss_address(CS_SWITCH_STATE_SELECTIVE_REVISION_NUMBER, revision_number) | ||
| response = self.__send_lss_address(CS_SWITCH_STATE_SELECTIVE_SERIAL_NUMBER, serial_number) | ||
|
|
||
| cs = struct.unpack_from("<B", response)[0] | ||
| if cs == CS_SWITCH_STATE_SELECTIVE_RESPONSE: | ||
|
|
@@ -203,19 +202,21 @@ def store_configuration(self): | |
| self.__send_configure(CS_STORE_CONFIGURATION) | ||
|
|
||
| def send_identify_remote_slave(self, | ||
| vendorId, productCode, | ||
| revisionNumberLow, revisionNumberHigh, | ||
| serialNumberLow, serialNumberHigh): | ||
|
|
||
| vendor_id, | ||
| product_code, | ||
| revision_number_low, | ||
| revision_number_high, | ||
| serial_number_low, | ||
| serial_number_high): | ||
| """This command sends the range of LSS address to find the slave nodes | ||
| in the specified range | ||
|
|
||
| :param int vendorId: | ||
| :param int productCode: | ||
| :param int revisionNumberLow: | ||
| :param int revisionNumberHigh: | ||
| :param int serialNumberLow: | ||
| :param int serialNumberHigh: | ||
| :param int vendor_id: | ||
| :param int product_code: | ||
| :param int revision_number_low: | ||
| :param int revision_number_high: | ||
| :param int serial_number_low: | ||
| :param int serial_number_high: | ||
|
|
||
| :return: | ||
| True if any slave responds. | ||
|
|
@@ -225,12 +226,12 @@ def send_identify_remote_slave(self, | |
|
|
||
| # TODO it should handle the multiple respones from slaves | ||
|
|
||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_VENDOR_ID, vendorId) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_PRODUCT_CODE, productCode) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_REVISION_NUMBER_LOW, revisionNumberLow) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_REVISION_NUMBER_HIGH, revisionNumberHigh) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_SERIAL_NUMBER_LOW, serialNumberLow) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_SERIAL_NUMBER_HIGH, serialNumberHigh) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_VENDOR_ID, vendor_id) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_PRODUCT_CODE, product_code) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_REVISION_NUMBER_LOW, revision_number_low) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_REVISION_NUMBER_HIGH, revision_number_high) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_SERIAL_NUMBER_LOW, serial_number_low) | ||
| self.__send_lss_address(CS_IDENTIFY_REMOTE_SLAVE_SERIAL_NUMBER_HIGH, serial_number_high) | ||
|
|
||
| def send_identify_non_configured_remote_slave(self): | ||
| # TODO it should handle the multiple respones from slaves | ||
|
|
@@ -261,7 +262,7 @@ def fast_scan(self): | |
| lss_bit_check -= 1 | ||
|
|
||
| if not self.__send_fast_scan_message(lss_id[lss_sub], lss_bit_check, lss_sub, lss_next): | ||
| lss_id[lss_sub] |= 1<<lss_bit_check | ||
| lss_id[lss_sub] |= 1 << lss_bit_check | ||
|
|
||
| time.sleep(0.01) | ||
|
|
||
|
|
@@ -289,7 +290,7 @@ def __send_fast_scan_message(self, id_number, bit_checker, lss_sub, lss_next): | |
|
|
||
| cs = struct.unpack_from("<B", recv_msg)[0] | ||
| if cs == CS_IDENTIFY_SLAVE: | ||
| return True | ||
| return True | ||
|
|
||
| return False | ||
|
|
||
|
|
@@ -391,6 +392,7 @@ def __send_command(self, message): | |
| return response | ||
|
|
||
| def on_message_received(self, can_id, data, timestamp): | ||
| _ = can_id, timestamp | ||
|
Collaborator
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. This was a nifty way of consuming unused arguments! |
||
| self.responses.put(bytes(data)) | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import threading | ||
| import logging | ||
| import struct | ||
| import threading | ||
| import time | ||
| from typing import Callable, Optional | ||
|
|
||
|
|
@@ -86,10 +86,7 @@ def state(self) -> str: | |
| - 'RESET' | ||
| - 'RESET COMMUNICATION' | ||
| """ | ||
| if self._state in NMT_STATES: | ||
| return NMT_STATES[self._state] | ||
| else: | ||
| return self._state | ||
| return NMT_STATES.get(self._state, "") | ||
|
Collaborator
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. Is this replacement the same as the former code? What about: return NMT_STATES.get(self._state, self._state) |
||
|
|
||
| @state.setter | ||
| def state(self, new_state: str): | ||
|
|
@@ -180,7 +177,8 @@ def start_node_guarding(self, period: float): | |
| :param period: | ||
| Period (in seconds) at which the node guarding should be advertised to the slave node. | ||
| """ | ||
| if self._node_guarding_producer : self.stop_node_guarding() | ||
| if self._node_guarding_producer: | ||
| self.stop_node_guarding() | ||
| self._node_guarding_producer = self.network.send_periodic(0x700 + self.id, None, period, True) | ||
|
|
||
| def stop_node_guarding(self): | ||
|
|
@@ -227,6 +225,7 @@ def send_command(self, code: int) -> None: | |
| self.update_heartbeat() | ||
|
|
||
| def on_write(self, index, data, **kwargs): | ||
| _ = kwargs | ||
| if index == 0x1017: | ||
| heartbeat_time, = struct.unpack_from("<H", data) | ||
| if heartbeat_time == 0: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 change is strictly speaking a change in interface. It will break if someone use named arguments to call this function.