revert some changes to TypedDict which crept in via Flux#449
Conversation
Summary of ChangesHello @andre-merzky, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses and reverts specific modifications that were previously introduced into the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #449 +/- ##
==========================================
+ Coverage 61.19% 61.21% +0.01%
==========================================
Files 66 66
Lines 7363 7359 -4
==========================================
- Hits 4506 4505 -1
+ Misses 2857 2854 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the TypedDict class initialization and setter methods to simplify the code and fix initialization order issues. The changes ensure that _data is properly initialized lazily before any update operations occur.
- Simplified
__init__method by consistently usingupdate()for all initialization paths - Removed redundant
_checkconditionals in setter methods by always calling_verify_setter - Added lazy initialization of
_datain__getattr__to prevent initialization order issues
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if from_dict: | ||
| self.update(from_dict) | ||
| self.update(from_dict) |
There was a problem hiding this comment.
Calling self.update(from_dict) when from_dict is None will cause an AttributeError since None does not have an items() method. While the update() method checks if not other:, this will only skip None and empty dicts. However, the call is unconditional here. Consider adding a conditional check before calling update(from_dict), similar to how kwargs is handled on line 167.
| self.update(from_dict) | |
| if from_dict is not None: | |
| self.update(from_dict) |
| self._data[k] = self._verify_setter(k, v) | ||
| else: | ||
| self._data[k] = v | ||
| self._data[k] = self._verify_setter(k, v) |
There was a problem hiding this comment.
[nitpick] The _verify_setter method at line 461 returns v unchanged when _check is False or when there is no _schema. By removing the if self._check: conditional here and always calling _verify_setter, the behavior is preserved for cases where _check is True. However, this now adds an extra function call overhead even when _check is False. While functionally correct, this could be a minor performance regression for the common case where _check is False (the default). Consider whether this performance tradeoff is acceptable.
| self._data[k] = self._verify_setter(k, v) | |
| if self._check: | |
| self._data[k] = self._verify_setter(k, v) | |
| else: | |
| self._data[k] = v |
There was a problem hiding this comment.
Code Review
This pull request reverts some recent changes to TypedDict and introduces related cleanups. The changes are sound and improve the code's consistency and maintainability. Using self.update() for default values in __init__ ensures consistent processing, and the lazy initialization of _data in __getattr__ makes the implementation more robust. The removal of redundant checks in __setitem__ and __setattr__ is a good cleanup. I have reviewed the changes and found no issues.
This is a response to https://github.com/radical-cybertools/radical.utils/pull/448/files#r2479162935