refactor: simplify parsing internals and fix duplicate deprecation warnings#384
Open
henryiii wants to merge 1 commit into
Open
refactor: simplify parsing internals and fix duplicate deprecation warnings#384henryiii wants to merge 1 commit into
henryiii wants to merge 1 commit into
Conversation
…rnings
- Collapse duplicate generator-parsing branches in LHEInit._fromcontext
into a single construction using element.attrib.get("name", "")
- Replace hand-rolled _indent helper with stdlib ET.indent (Python 3.9+),
preserving byte-identical output by setting root.tail = "\n"
- Tighten type annotations: _fromcontext context params typed as
Iterator[tuple[str, ET.Element]]; LHEHeader._fromcontext return type
narrowed from Union["LHEHeader", None] to "LHEHeader"
- Remove dead falsy check on w in weights parsing (str.split() items
are never empty); raise clear ValueError when <weights> block has more
entries than <initrwgt> declares (was a cryptic KeyError)
- Fix LHEParticle.mothers() to use self._event internally so it emits
exactly one DeprecationWarning per call instead of four; add assertion
to test suite verifying the warning count
Assisted-by: ClaudeCode:claude-sonnet-4-6
🏎️ Benchmark Comparison |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #384 +/- ##
===========================================
- Coverage 100.00% 99.66% -0.34%
===========================================
Files 2 2
Lines 608 597 -11
===========================================
- Hits 608 595 -13
- Misses 0 2 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
🤖 AI text below 🤖
Summary
Internal-only cleanups to
src/pylhe/__init__.py— no public API changes.LHEInit._fromcontexthad two near-identical branches for lhe-v3 (name + version) and lhe-v2 (version only). Collapsed into a singleLHEGenerator(name=element.attrib.get("name", ""), ...)construction; behavior is identical._indentwith stdlibET.indent: Deleted the Stack Overflow copy-paste_indenthelper (added pre-3.9) and replaced both call sites withET.indent(root, space=" ")+root.tail = "\n". Output is byte-identical; confirmed by existing writer tests.LHEHeader._fromcontextreturn type narrowed fromUnion["LHEHeader", None]to"LHEHeader"(it never returns None)._fromcontextcontextparameters typed fromAnytoIterator[tuple[str, ET.Element]].if wguard in<weights>parsing (items fromstr.split()are never falsy).KeyErrorwhen<weights>has more entries than<initrwgt>declares with a clearValueErrorincluding entry counts.mothers()emits exactly one warning:LHEParticle.mothers()was internally accessingself.event(the deprecated property) three times, emitting 3 extraDeprecationWarnings per call. Changed to useself._eventdirectly. Test updated to assert exactly one warning per call.Part of #378
Test plan
uv run pytest— 121 passed, 0 faileduv run mypy— no issuesprek -a --quiet— all hooks pass🤖 Generated with Claude Code