-
Couldn't load subscription status.
- Fork 234
Description
Hello,
First, thank you for your work on this very useful library.
I'm trying to correctly handle the return value of the FtdiEeprom.commit() method and I would appreciate some clarification, as I might be misunderstanding its intended behavior.
The Issue
The method's docstring states:
:return: True if some changes have been committed to the EEPROMHowever, the implementation's final line is:
return dry_runThis means that when calling the method to perform an actual write, like eeprom.commit(dry_run=False), the function will always return False upon successful completion.
This breaks the standard way of checking if the operation was performed:
# Assume the EEPROM buffer has been modified...
changes_committed = eeprom.commit(dry_run=False)
if changes_committed:
# This block is never reached, even after a successful write.
print("✅ Programming successful.")
else:
# This block is always executed, giving a misleading message.
print("No changes were needed.")Analysis
The logic for writing to the device and verifying the write seems correct. If the write fails, an FtdiEepromError is properly raised. The only issue is the final return value, which does not reflect whether a change was committed, but rather the mode in which the function was called.
Suggested Solution
A potential fix would be to make the code align with the docstring's intent. The function could return True after a successful write (i.e., when dry_run is False and no exception was raised). The existing if not self._modified: check already correctly returns False when there's nothing to commit.
For example, the end of the function could be changed to:
# ... (inside the 'if not dry_run:' block, after verification)
self._modified = False
# If we get here, it means the commit was attempted.
# Return True if it was a real write, False if it was a dry_run
# or if nothing was modified.
return not dry_runMy primary question is: could you clarify if this is the intended behavior? Perhaps I am not using the correct pattern to verify if a write operation was successful. Is there a recommended way to check for a successful commit besides the return value?
Thank you for your time and guidance. I appreciate any insight you can provide.