update type handling#16
Closed
FriendlyUser1 wants to merge 2 commits into
Closed
Conversation
Reviewer's GuideAdds stronger typing across database utilities and the entry modal, including a dedicated EntryDetails TypedDict, and makes small behavioral tweaks to entry/group iteration and the notes text area label. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues, and left some high level feedback:
- In
merge_entry, theif current_group != Group:check will always be true becauseGroupis a type, not an instance; if you intend to validate the type, useisinstance(current_group, Group)(or drop the check ifroot_groupis already guaranteed to be aGroup). - The change to
show_entry_detailsto defaultkeyto""and always usekey=f"notes_{key}"means calls that omitkeywill all share the same Streamlit widget key ("notes_"), which can cause state collisions; consider keepingkeyasOptional[str]and passingNonethrough when not provided.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `merge_entry`, the `if current_group != Group:` check will always be true because `Group` is a type, not an instance; if you intend to validate the type, use `isinstance(current_group, Group)` (or drop the check if `root_group` is already guaranteed to be a `Group`).
- The change to `show_entry_details` to default `key` to `""` and always use `key=f"notes_{key}"` means calls that omit `key` will all share the same Streamlit widget key (`"notes_"`), which can cause state collisions; consider keeping `key` as `Optional[str]` and passing `None` through when not provided.
## Individual Comments
### Comment 1
<location path="KeePassDiff/utils/database.py" line_range="117" />
<code_context>
current_group = target_kp.root_group
+
for group_name in group_path:
+ if current_group != Group:
+ return False
+
</code_context>
<issue_to_address>
**issue (bug_risk):** The `current_group != Group` check will always be true and prevents `merge_entry` from progressing.
Here `current_group` is an instance and `Group` is the class, so this comparison is always `True`. As a result, the loop returns `False` on its first iteration whenever `group_path` is non-empty, breaking merges for nested entries. If the goal is a type check, use `isinstance(current_group, Group)` and only return `False` when that fails, or remove this condition if `current_group` is already guaranteed to be a `Group`.
</issue_to_address>
### Comment 2
<location path="KeePassDiff/utils/database.py" line_range="120" />
<code_context>
+ if current_group != Group:
+ return False
+
next_group = next((g for g in current_group.subgroups if g == group_name), None)
if not next_group:
next_group = target_kp.add_group(current_group, group_name)
</code_context>
<issue_to_address>
**issue (bug_risk):** Comparing `Group` instances directly to `group_name` may never match and could cause redundant group creation.
Here `g` is a `Group` instance while `group_name` is a string, so this comparison will always fail unless `Group.__eq__` is specially implemented. That means you’ll always create a new subgroup instead of reusing existing ones. Compare the group’s identifier (e.g. `g.name` or `str(g)`) to `group_name` instead.
</issue_to_address>
### Comment 3
<location path="KeePassDiff/components/entry_modal.py" line_range="7-8" />
<code_context>
-def show_entry_details(entry_details: Optional[Dict] = None, key: str = None):
+def show_entry_details(
+ entry_details: EntryDetails | None = None,
+ key: str = "",
+):
if entry_details:
</code_context>
<issue_to_address>
**issue (bug_risk):** Changing `key` to default to an empty string may introduce unintended Streamlit key collisions.
With this change, any call that omits `key` will use the same underlying widget key (`"notes_"`), so multiple `show_entry_details` instances without explicit keys will share state in Streamlit. Consider keeping `key: str | None = None` and only prefixing when `key is not None`, or generating a unique key internally for each call.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
6d7af3d to
eff1d55
Compare
Contributor
Author
|
closing to bundle these changes with larger diff updates |
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.
This adds type checking, and improved types for multiple functions.
Class EntryDetails has been created since the upstream pykeepass package has poor typing, though may be fixed in future
I have also added a label to the entry modal notes text area (which is encouraged by streamlit) and set its visibility to collapsed which removes the gap above the note box.
Summary by Sourcery
Improve type safety and robustness across KeePass utilities and entry UI, while refining the entry comparison output typing.
Enhancements: