748: handle obj.get(k, default) call pattern for backward compatibility#755
Merged
lognaturel merged 1 commit intoXLSForm:masterfrom Feb 21, 2025
Merged
Conversation
- not used internally but for external libs that assume Mapping == dict - test case notes other differences from default dict behaviour
4 tasks
lognaturel
approved these changes
Feb 21, 2025
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.
Closes #748
Why is this the best possible solution? Were any other approaches considered?
obj.get(key, default)with SurveyElement if neededAlternatives
The original code in #748 meant that
elem.get("foo")would return None. This seemed seemed like it would be confusing for pyxform maintenance since a) there is still someelem.get("foo")code, and b) its easier to only be concerned about AttributeErrors (as would be expected for a non-dict class) rather than a mix of None, KeyError, AttributeError. If calling code likeelem.get("foo")expects None then it can be adapted to use an explicitNonedefault e.g.elem.get("foo", None)- otherwise it will raise an AttributeError as before. TheSurveyElementalso differs fromdictinelem["foo"](AttributeError not KeyError, respectively) so it didn't seem appropriate to fully replicatedictbehaviour in this custom Mapping class.Other alternatives mentioned in #748 and the warning message, for external libs to implement:
What are the regression risks?
There are no internal calls like
obj.get(key, default). External code should work as before, except for the DeprecationWarning which can be ignored as shown in the tests, i.e. add:Does this change require updates to documentation? If so, please file an issue here and include the link below.
No.
Before submitting this PR, please make sure you have:
testspython -m unittestand verified all tests passruff format pyxform testsandruff check pyxform teststo lint code