Skip to content

Ship the py.typed marker in the Python wheel - #34010

Open
Danny On The Air (dannyota) wants to merge 1 commit into
microsoft:mainfrom
dannyota:python/py-typed-wheel
Open

Danny On The Air (dannyota) wants to merge 1 commit into
microsoft:mainfrom
dannyota:python/py-typed-wheel

Conversation

@dannyota

Copy link
Copy Markdown
Contributor

Description

#28438 added onnxruntime/py.typed and listed it in setup.py package_data, but setup.py runs in the build tree and CMake never copied the marker there. Wheels still ship without it (checked the 1.31.1 wheel), so mypy reports import-untyped.

  • Copy py.typed next to __init__.py in cmake/onnxruntime_python.cmake.
  • Run the existing test_pep561_py_typed_marker.py with the other Python tests in build.py. Linux wheel CI runs it against the installed wheel.

Testing

  • macOS arm64 CPU wheel built with --build_wheel: onnxruntime/py.typed is in the wheel, the marker test passes against the installed wheel, and mypy on import onnxruntime reports no issues.
  • With the official 1.31.1 wheel, the same mypy check fails with import-untyped.

Motivation and Context

Fixes the mypy error reported in #32615. Type stubs for the pybind11 module are a separate step.

microsoft#28438 added onnxruntime/py.typed and listed it in setup.py's
package_data, but setup.py runs in the build tree and CMake never copied
the marker there. Released wheels (1.31.1) still lack it, so mypy keeps
reporting import-untyped (microsoft#32615).

Copy py.typed next to __init__.py, and run the existing PEP 561 marker
test with the other Python tests so the regression is caught.

Signed-off-by: Danny <dannyontheair@outlook.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 14:34
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the change to include the PEP 561 marker in Python wheels.

No open issues 🎉

What changed in this PR

Fixes the missing PEP 561 marker in Python wheels by copying py.typed into the build tree used for packaging. This completes the packaging work from #28438 and addresses the missing-marker cause of mypy’s import-untyped error reported in #32615.

Changes:

  • Copy py.typed alongside the package’s __init__.py.
  • Run the existing marker regression test with the Python test suite.
File Description
tools/​ci_build/​build.py Adds the existing PEP 561 marker test to Python test execution.
cmake/​onnxruntime_python.cmake Copies py.typed into the build-tree package for wheel inclusion.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants