Merged
Conversation
PCANBasic.GetValue() must always return a Tuple with 2 elements, otherwise PcanBus._detect_available_configs() raises a "not enough values to unpack" error at line 718.
zariiii9003
reviewed
Apr 23, 2024
| res = self.GetValue(Channel, PCAN_ATTACHED_CHANNELS_COUNT) | ||
| if TPCANStatus(res[0]) != PCAN_ERROR_OK: | ||
| return (TPCANStatus(res[0]),) | ||
| return TPCANStatus(res[0]), () |
Collaborator
There was a problem hiding this comment.
Suggested change
| return TPCANStatus(res[0]), () | |
| return TPCANStatus(res[0]), None |
Contributor
Author
There was a problem hiding this comment.
Since you expect to receive an Iterable, returning an empty tuple is better so you don't have to check if it is "None" before using it in a For loop.
Collaborator
There was a problem hiding this comment.
This is the error case. There is no valid result, so it is not used here:
python-can/can/interfaces/pcan/pcan.py
Line 720 in 7dba449
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
One of my colleagues encountered a "not enough values to unpack" error while scanning for connected dongles with PCAN drivers installed.
I couldn't replicate the error on my computer after installing the latest PCAN drivers. Still, analysing the instruction that raised that error, it seems that
PCANBasic.GetValue()returned a wrong Tuple for a specific error condition.That method must always return a Tuple with 2 elements, otherwise
PcanBus._detect_available_configs()raises a "not enough values to unpack" error at line 718.