Skip to content

generate: rewrite .pyi stub imports to relative form#14

Closed
Bre77 wants to merge 1 commit into
mainfrom
fm/proto-pyi-relative-imports
Closed

generate: rewrite .pyi stub imports to relative form#14
Bre77 wants to merge 1 commit into
mainfrom
fm/proto-pyi-relative-imports

Conversation

@Bre77

@Bre77 Bre77 commented Jul 22, 2026

Copy link
Copy Markdown
Member

Intent

  • Generated Python .pyi type stubs use bare imports (import signatures_pb2 as _signatures_pb2) while the runtime .py files correctly use relative imports (from . import signatures_pb2 as ...), breaking strict-mode type resolution (pyright) for downstream Python consumers.
    • protoletariat's import rewriter only recognizes protoc's .py alias 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 .pyi cross-file imports even though it fixes the matching .py file.
    • Add scripts/fix_pyi_relative_imports.py, run after protol for each proto group in scripts/generate.sh, to rewrite that remaining alias convention to relative form.
  • Regenerated all packages; only .pyi files with cross-file imports changed. No proto or TypeScript output changed, so buf lint/buf breaking are unaffected.
  • Patch changeset added (generated-output fix, no proto/API change).

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.
@Bre77

Bre77 commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

Closing as a duplicate of #13, which already fixes the same .pyi bare-import issue at the generator level (post-protol fix_pyi_imports.py pass + regenerated stubs). #13 predates this and is complete; consolidating on it.

@Bre77 Bre77 closed this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant