Addressed all claude analysis recommendations of #1240#1246
Addressed all claude analysis recommendations of #1240#1246VisLab merged 4 commits intohed-standard:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens error semantics and improves developer-facing diagnostics across HED query parsing, group copying, and definition resolution, while also cleaning up debug scaffolding and expanding module/serializer documentation.
Changes:
- Introduces
HedQueryError(aValueErrorsubclass) and updates query parsing to raise it consistently, with new tests to lock in behavior. - Adjusts
HedGroupshallow-copy behavior to raisecopy.Errorand adds copy-focused tests. - Improves docstrings/error messages and removes leftover
__main__debug blocks in validator utilities.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/models/test_query_handler.py | Adds coverage ensuring broken queries raise HedQueryError (and remain catchable as ValueError). |
| tests/models/test_hed_group.py | Adds tests for shallow-copy failure (copy.Error) and successful deep-copy behavior. |
| hed/validator/util/char_util.py | Removes __main__ debug snippet. |
| hed/validator/reserved_checker.py | Removes __main__ debug snippet. |
| hed/schema/schema_io/schema2base.py | Substantially expands serializer base-class documentation and clarifies traversal order. |
| hed/schema/hed_schema_entry.py | Avoids duplicated inherited-attribute checks by computing once and reusing the value. |
| hed/schema/hed_schema.py | Removes commented-out debug prints from equality logic. |
| hed/schema/init.py | Adds richer package docstring explaining intended public API/usage. |
| hed/models/query_handler.py | Switches parse errors from ValueError to HedQueryError. |
| hed/models/hed_string.py | Documents the intentional fallback-to-empty-tree behavior on structural parse failures. |
| hed/models/hed_group.py | Changes shallow-copy exception type/message to copy.Error with guidance to use .copy(). |
| hed/models/def_expand_gather.py | Replaces generic “Invalid Definition” with more actionable ValueError messages. |
| hed/models/column_mapper.py | Moves partial import to module scope and removes redundant inline imports/branches. |
| hed/models/init.py | Adds richer package docstring explaining intended public API/usage. |
| hed/errors/exceptions.py | Adds the new HedQueryError exception type. |
| hed/init.py | Re-exports HedQueryError at package top-level. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Review: #1246 — Addressed Claude analysis recommendations of #1240Overall: Clean, well-structured PR. No critical issues. The changes fall into four categories: better exception granularity, documentation improvements, dead code cleanup, and a minor refactoring. HedQueryError (exceptions.py / query_handler.py)Well designed. Inheriting from copy.Error in HedGroup.copy (hed_group.py)
_finalize_inherited_attributes refactoring (hed_schema_entry.py)The old code called This is safe because Documentation
Cleanup
Minor issues (inline)See inline comments below. |
PR Review: #1246 — Addressed Claude analysis recommendations of #1240Overall: Clean, well-structured PR. No critical issues. The changes fall into four categories: better exception granularity, documentation improvements, dead code cleanup, and a minor refactoring. HedQueryError (exceptions.py / query_handler.py)Well designed. Inheriting from copy.Error in HedGroup.copy (hed_group.py)
One BC note: _finalize_inherited_attributes refactoring (hed_schema_entry.py)The old code called This is safe because _output_extras now called in process_schema (schema2base.py)This PR adds Documentation
Cleanup
Minor issues (inline)See inline comments below. |
| with self.subTest(query=string): | ||
| # Must be the specific subclass, not a plain ValueError | ||
| with self.assertRaises(HedQueryError): | ||
| QueryHandler(string) |
There was a problem hiding this comment.
Suggestion — duplicate coverage
test_broken_search_strings_raise_hed_query_error tests exactly the same six broken strings as the existing test_broken_search_strings (lines 41-46). Since HedQueryError IS a ValueError, the old test already implicitly passes for the new type. Consider either:
- Replacing the old test's
assertRaises(ValueError)withassertRaises(HedQueryError)(which covers both, sinceHedQueryErroris aValueError), or - Adding a comment explaining why the duplication is intentional (e.g., to guard against accidentally reverting the type to plain
ValueError).
| hed_string = HedString("(Tag1, Tag2)", self.hed_schema) | ||
| group = hed_string.get_first_group() | ||
|
|
||
| deep = copy.deepcopy(group) |
There was a problem hiding this comment.
Suggestion — _parent state is not verified
copy.deepcopy(group) is called while group._parent still points to hed_string. Python's cycle-detection handles this correctly, but the resulting deep object will have _parent set to a deep copy of the entire HedString tree — which is different from the documented group.copy() behaviour (where _parent is None in the returned copy).
The test only checks str(deep) == str(group), which passes regardless. If the intent is to document that raw deepcopy is safe, add an assertion (or at least a comment) noting that deep._parent will be a copy of the parent, not None. If the intent is to test the public deep-copy API, group.copy() (already tested on line 137) is the right path.
No description provided.