Preserve public prefix when round-tripping Import declarations#990
Merged
Conversation
`Import.__str__` hardcoded `'import '`, so `public import IntDefs` round-tripped to `import IntDefs`, which both parsers reinterpret as a non-public import. Emit the `public ` prefix when `visibility == 'public'`, matching the existing surface form. Adds `public_import_roundtrip.pf` and wires it into `PARSER_ROUND_TRIP_FILES` so the round-trip harness covers the `public import` surface form going forward. Addresses #988 (category (a)). Refs #931, #987. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Import.__str__now emits apublicprefix whenvisibility == 'public'. Previously,public import IntDefsround-tripped to plainimport IntDefs, which both parsers re-interpret as a non-public (private/default) import, dropping the visibility from the canonical AST.test/should-validate/public_import_roundtrip.pfand wires it intoPARSER_ROUND_TRIP_FILESso the round-trip harness covers thepublic importsurface form going forward.Round-trip sweep over
lib/+test/should-validate/now shows 10 mismatches (was 13); the three files that flipped to clean (lib/Int.pf,lib/IntDefs.pf,lib/UInt.pf) are exactly the ones whose only remaining drift waspublic import …per #988(a). The remaining 10 are the other three umbrella categories (b)/(c)/(d) and thenot Xprecedence drift tracked separately in #987.Addresses #988 (category (a)). Refs #931, #987.
Test plan
make static(ruff + mypy +mypy --no-site-packages) — clean.python test-deduce.py --equiv— passes, including the newpublic_import_roundtrip.pfentry in the round-trip list.lib/Int.pf:public import IntDefsnow pretty-prints aspublic import IntDefsunder both RD and LALR parsers.python deduce.py --dir test/test-imports test/should-validate/public_import_roundtrip.pf—is valid.Claude session — fallback UUID:
136d134c-5a7e-4ac6-9e7f-b7f1a6cdada5🤖 Generated with Claude Code