Repository navigation
fix(python): expand a ::-relative package against the declaring file's root package - #405
Merged
Merged
Conversation
…s root package
The Python parser kept a relative package ("::parts") raw, and later code expanded
it against the merged root's package, which is the first file's. In a multi-file
collection whose files declare different root packages that gave a different
package, resolution key, canonical JSON and field-lint address than TypeScript, C#
and Java. The parser now expands at parse time against the declaring file's
context package, mirroring TS applyReservedKeys.
- field_lint.py drops its own expansion of the loaded model and shares the
parser's helper for the raw-file walk.
- MetaData.effective_package() exposes the package a node resolves under.
- New conformance fixture loader-relative-package-multi-root and field-lint
fixture reference-field-missing-multi-root-package gate every port.
- The Python corner note in the field-lint docs is removed.
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.
Intent
Yes expand like the others: make the Python parser expand a
::-relative package against the declaring file's root package at parse time, the same as TypeScript, C# and Java.Background: in a multi-file collection whose files declare different root packages, an object that declares a
::-relative package (for example::parts) is expanded by Python against the merged root's package, while TypeScript, C# and Java expand it against the declaring file's root package. Themeta verifyfield-lint warnings (PR #404) therefore print a different address in Python for that case (for exampleacme::app::parts::Gadget.store_fkwhere the other ports printbeta::other::parts::Gadget.store_fk), and that PR documents the difference as a known Python corner. Own small gated PR; the gate spend is approved.What Changed
Parser package expansion: Python now expands
::-relative packages (e.g.,"package": "::parts") during parsing against the declaring file's root package, matching TypeScript, C# and Java behavior. Previously the expansion was deferred and used the merged collection's root package, causing mismatches in multi-file models where files declare different root packages.New
effective_package()method: Added toMetaDatato distinguish between a node's declaredpackage(which isNoneif inherited) and the package it resolves under, mirroring the C#NamingRefs.EffectivePackagecontract.Conformance fixtures: Added
loader-relative-package-multi-rootto the cross-language conformance suite andreference-field-missing-multi-root-packageto field-lint conformance, gating the fix across all five ports so field-lint warnings now print consistent addresses.Risk Assessment
✅ Low: Small, well-scoped parser fix with shared helper, matching cross-port conformance fixture, and dedicated unit/conformance tests covering the new behavior and the extracted effective_package accessor.
Testing
Python parser expansion validated across 5 live scenarios: relative package expansion at parse time against declaring file root, multi-file collection resolution, field-lint address consistency, effective_package() API, and conformance fixtures. All 1251 unit/loader/conformance tests pass with no regressions.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
scripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchainspython3 -m pytest tests/loader/test_relative_package_multi_root.py::test_relative_package_expands_against_declaring_file_rootpython3 -m pytest tests/loader/test_relative_package_multi_root.py::test_effective_package_of_an_object_without_own_packagepython3 -m pytest tests/conformance/test_field_lint_conformance.py::test_fixture[reference-field-missing-multi-root-package]python3 -m pytest tests/unit tests/loader tests/conformance(1251 tests: unit + loader + conformance)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.