fix(client): raise AttributeError, not KeyError, for missing dunders#290
Draft
bluetoothbot wants to merge 1 commit into
Draft
fix(client): raise AttributeError, not KeyError, for missing dunders#290bluetoothbot wants to merge 1 commit into
bluetoothbot wants to merge 1 commit into
Conversation
ONVIFService.__getattr__ returned self.__dict__[name] for any unset dunder, which raises KeyError. __getattr__ only fires after normal lookup fails, so this always raised KeyError instead of the AttributeError the Python data model requires. The KeyError leaked out of hasattr() and the 3-arg getattr() fallback, and broke copy.deepcopy(), which probes __deepcopy__ on the instance. Raise AttributeError(name) instead. Update the test that pinned the old KeyError behavior and add coverage proving hasattr/getattr-default/deepcopy now behave transparently.
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
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.
What:
ONVIFService.__getattr__now raisesAttributeErrorfor missing dunders instead ofKeyError.Why:
__getattr__only runs after normal attribute lookup fails, so the oldreturn self.__dict__[name]always raisedKeyError. Python's data model requiresAttributeErrorhere — aKeyErrorescapeshasattr()and the 3-arggetattr(obj, name, default)fallback (both only suppressAttributeError), and it breakscopy.deepcopy(), which probes__deepcopy__on the instance:How: Replaced
return self.__dict__[name]withraise AttributeError(name), keeping the original intent (don't proxy dunder access to the ONVIF operation dispatcher). Updated the test that pinned the oldKeyErrorbehavior and added coverage for the stdlib protocols above.Testing:
pytest(256 passed),ruff checkclean.Quality Report
Changes: 87 files changed, 9581 insertions(+), 1475 deletions(-)
Code scan: 20 issue(s) found
README.rst:61— debug print statementREADME.rst:111— debug print statementexamples/events.py:20— debug print statementexamples/events.py:24— debug print statementexamples/events.py:25— debug print statementexamples/events.py:27— debug print statementexamples/events.py:29— debug print statementexamples/events.py:62— debug print statementexamples/events.py:74— debug print statementexamples/events.py:84— debug print statementTests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan