generate: rewrite .pyi stub imports to relative form#14
Closed
Bre77 wants to merge 1 commit into
Closed
Conversation
protoletariat's rewriter only recognizes protoc's .py import-alias convention (import x_pb2 as x__pb2), not the pyi-stub generator's convention (import x_pb2 as _x_pb2), so it silently left .pyi cross-file imports unrewritten while correctly fixing the matching .py file. This broke strict-mode type resolution (pyright) for downstream Python consumers. Add scripts/fix_pyi_relative_imports.py, run after protol in scripts/generate.sh, to cover that alias convention.
Member
Author
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
.pyitype stubs use bare imports (import signatures_pb2 as _signatures_pb2) while the runtime.pyfiles correctly use relative imports (from . import signatures_pb2 as ...), breaking strict-mode type resolution (pyright) for downstream Python consumers..pyalias convention (import x_pb2 as x__pb2); the built-in pyi-stub generator uses a different alias convention (import x_pb2 as _x_pb2), so protoletariat silently skips rewriting.pyicross-file imports even though it fixes the matching.pyfile.scripts/fix_pyi_relative_imports.py, run afterprotolfor each proto group inscripts/generate.sh, to rewrite that remaining alias convention to relative form..pyifiles with cross-file imports changed. No proto or TypeScript output changed, sobuf lint/buf breakingare unaffected.