frozen RenderedSubstituentName dataclass - #46
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Reviewer's GuideThis PR converts RenderedSubstituentName from a string subclass into a frozen dataclass carrying explicit boundary metadata, propagates the new RenderedSubstituentText type through naming/trace APIs, and tightens tree metadata validation and parentheses-handling logic without changing naming semantics. Sequence diagram for rendered substituent boundary propagationsequenceDiagram
participant Namer
participant name_subgraph
participant AssemblyParts
participant add_substituent_trace
participant format_substituent_prefixes
Namer->>name_subgraph: name_subgraph(mol,start_idx,exclude_atoms,upstream_atom)
name_subgraph->>AssemblyParts: _assemble_parent_name(mol,parts,numbered_path,finalize_subgraph=true)
AssemblyParts-->>name_subgraph: RenderedSubstituentName
name_subgraph->>name_subgraph: split_rendered_substituent_name(rendered_name)
name_subgraph-->>Namer: RenderedSubstituentText
Namer->>add_substituent_trace: add_substituent_trace(parts,name,locant,...,outer_parentheses_optional=None)
add_substituent_trace->>add_substituent_trace: split_rendered_substituent_name(name)
add_substituent_trace->>AssemblyParts: update SubstituentItem.outer_parentheses_optional
Namer->>format_substituent_prefixes: format_substituent_prefixes(parts,spiro_subs)
format_substituent_prefixes->>format_substituent_prefixes: _omit_optional_outer_parentheses(...,outer_parentheses_optional)
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 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/openclatura/tests/test_analysis.py" line_range="311-316" />
<code_context>
assert shortcut["substituents"] == []
+def test_tree_builder_rejects_unknown_or_invariant_metadata_fields():
+ with pytest.raises(ValueError, match="Unknown tree metadata fields"):
+ build_naming_tree_node(kind="component", name="methane", metadata={"unexpected": []})
+
+ with pytest.raises(ValueError, match="cannot replace invariant fields"):
+ build_naming_tree_node(kind="component", name="methane", metadata={"name": "other"})
+
+
</code_context>
<issue_to_address>
**suggestion (testing):** Add a positive test case that valid metadata is accepted and merged without errors.
To fully exercise the new `NamingTreeMetadata` and `NAMING_TREE_METADATA_FIELDS` logic, please also add a test that passes metadata with all supported keys (`name_atom_bindings`, `name_token_spans`, `stereo_features`, `indicated_hydrogens`, `hydro_operations`, `parent_charges`) and verifies `build_naming_tree_node` returns a node containing these keys plus the invariant fields without raising. This will validate the whitelist and merge behavior, not just the rejection paths.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| def test_tree_builder_rejects_unknown_or_invariant_metadata_fields(): | ||
| with pytest.raises(ValueError, match="Unknown tree metadata fields"): | ||
| build_naming_tree_node(kind="component", name="methane", metadata={"unexpected": []}) | ||
|
|
||
| with pytest.raises(ValueError, match="cannot replace invariant fields"): | ||
| build_naming_tree_node(kind="component", name="methane", metadata={"name": "other"}) |
There was a problem hiding this comment.
suggestion (testing): Add a positive test case that valid metadata is accepted and merged without errors.
To fully exercise the new NamingTreeMetadata and NAMING_TREE_METADATA_FIELDS logic, please also add a test that passes metadata with all supported keys (name_atom_bindings, name_token_spans, stereo_features, indicated_hydrogens, hydro_operations, parent_charges) and verifies build_naming_tree_node returns a node containing these keys plus the invariant fields without raising. This will validate the whitelist and merge behavior, not just the rejection paths.
Summary by Sourcery
Track and propagate optional outer-parenthesis boundary metadata on rendered substituent names using a frozen dataclass wrapper, and tighten naming-tree metadata validation.
Enhancements:
Tests: