Skip to content

fix: correct generated Python stub types - #9226

Open
27av03 wants to merge 1 commit into
google:masterfrom
27av03:fix/python-generated-stubs
Open

fix: correct generated Python stub types#9226
27av03 wants to merge 1 commit into
google:masterfrom
27av03:fix/python-generated-stubs

Conversation

@27av03

@27av03 27av03 commented Sep 5, 2026

Copy link
Copy Markdown

Summary

Fixes issues in generated Python type stubs produced with --python-typing.

  • removes the generated uoffset type alias, which does not exist in the corresponding runtime module
  • uses int directly for builder offset parameters and return types
  • only imports NumPy when a generated stub actually exposes an AsNumpy() method
  • uses numpy.ndarray annotations when NumPy is required
  • regenerates affected .pyi fixtures

Fixes #9224.

Validation

  • reproduced the original issue with a minimal schema
  • verified generated stubs no longer reference uoffset or flatbuffers.number_types
  • verified schemas without NumPy-backed vector accessors no longer import NumPy
  • verified schemas with AsNumpy() still generate valid NumPy annotations
  • tests/PythonTest.sh
  • python3 scripts/check_generate_code.py
  • sh scripts/clang-format-git.sh

Remove the generated uoffset alias from Python type stubs and use int
directly for builder offset parameters and return types.

Only import NumPy in stubs that actually emit AsNumpy() annotations,
and use numpy.ndarray for those annotations.

Validated with PythonTest.sh, check_generate_code.py, and clang-format.

Signed-off-by: anayv <meanayvarma@gmail.com>
@27av03
27av03 requested a review from dbaileychess as a code owner September 5, 2026 01:34
@github-actions github-actions Bot added python c++ codegen Involving generating code from schema labels Sep 5, 2026
@google-cla

google-cla Bot commented Sep 5, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Generated type stubs don't work

1 participant