Unify name/wildcard/regex lookup and miss-behavior across holders - #449
Open
gupichon wants to merge 2 commits into
Conversation
gupichon
requested review from
JeanLucPons,
TeresiaOlsson and
gubaidulinvadim
September 18, 2026 15:17
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.
Description
Name-based lookup (
__getitem__,.get(),find_elements()) was implemented independently in at least six places acrossElementHolderand the holder/array hierarchy, each with its own idea of what counts as a wildcard, whetherre:regex is supported, and what happens on a miss (None, an exception,AttributeError, or a silent empty result). This surfaced while addingToolHolder(#375):sr.live.bpm["BPM_001"]raisedTypeError(no__getitem__on singular holders) whilesr.live["BPM_001"]andsr.live.bpms["BPM_001"]both "worked" with disagreeing semantics. This PR defines one shared name/wildcard resolution convention (pyaml/common/name_matching.py) and applies it consistently to every holder and array.Related Issue
Features/issues described there are:
__getitem__toGenericElementHolder,RFHolder,RFTransmitterHolder,ToolHolder, andDiagnosticHolder— implemented by routing all of them, plus the existingElementHolder.__getitem__/find_elements()andElementArray.__getitem__/GenericArrayHolder.__getitem__, through one shared resolver (resolve_names()/is_wildcard()) instead of each reimplementing its own rules.fnmatch.fnmatch()normalizes throughos.path.normcase(), so the same wildcard pattern matched case-insensitively on Windows and case-sensitively on Linux CI — switched every call site tofnmatch.fnmatchcase().re:-prefixed regex used to leak a rawre.error; it now raisesPyAMLExceptionlike every other lookup failure.GenericArrayHolder.__getitem__(e.g.magnets["QF1*"]) keeps searching individual element names, not registered array/family names — this is Feature: Complete magnet holder navigation #373's recent, deliberately tested behavior. Documented explicitly instead of unifying it with.get(name)'s separate array/family-name namespace, since unifying would revert Feature: Complete magnet holder navigation #373.__getitem__toDiagnosticHolderandRFTransmitterHolder, which have the exact same shape asRFHolder/ToolHolderand didn't exist yet when the issue was written (they landed with Feature: Add a public diagnostic holder #372 and Feature: Add a public tuning and measurement tool holder #375).re:prefix) is kept, reversing what the issue currently says, and extended everywhere the resolver is used, not justfind_elements(). A list/tuple of patterns (literal, wildcard, or regex, mixed) is also now accepted everywhere a single pattern is, unioned and de-duplicated.Changes to existing functionality
ElementHolder.__getitem__: a literal exact name with no match now raisesPyAMLExceptioninstead of returningNone. Breaking change — any caller relying on the oldNone-on-miss must now catchPyAMLExceptionor check membership first.ElementArray.__getitem__/GenericArrayHolder.__getitem__: same literal-miss fix (raises instead of silently returning an empty array); wildcard trigger now also includes[, not just*/?; case-sensitive matching viafnmatchcase; gainsre:and list-of-patterns support. A wildcard/regex pattern matching nothing is unaffected, still an empty collection, not an error.ElementHolder.find_elements(): reimplemented as a thin wrapper around the shared resolver, same public behavior plus the[-trigger, case-sensitivity, and error-wrapping fixes above, and now also accepts a list of patterns directly.Testing
The following tests (compatible with pytest) were added:
tests/common/test_name_matching.py: the shared resolver directly — literal hit/miss, wildcard hit/empty, regex hit/empty/invalid, case sensitivity, list-of-patterns (union/dedup/order, one missing literal raises)tests/common/test_element_holder_collection.py:ElementHolder.__getitem__/find_elements()literal-miss-raises,[-as-wildcard,re:, list-of-patterns, case sensitivity, plus new tests combining wildcard/regex/list selections with&/|/-set operations (non-trivial intersection/union/difference, and the empty-result-stays-a-plain-listquirk under the new selection styles)tests/arrays/test_array_selection_types.py:ElementArray.__getitem__literal-miss-raises, bracket-only wildcard, regex, list-of-patterns, case sensitivitytests/common/test_array_holder_navigation.py:GenericElementHolder.__getitem__via.magnet,.combined_function_magnet,.serialized_magnet; a realistic example reproducing theQForTestYAML exclusion family via[]selection and-tests/diagnostics/test_diagnostic_accessors.py:DiagnosticHolder.__getitem__and.diagnostic.bpm[...]tests/rf/test_rf_holder.py(new):RFHolder/RFTransmitterHolder.__getitem__tests/tuning_tools/test_tool_holder.py(new):ToolHolder.__getitem__Verify that your checklist complies with the project
pytest tests -n auto: 389 passed, 6 skipped; one unrelated pre-existing flake,test_tuning_orm, is a Windows temp-filePermissionErrorunconnected to this change)None)