Skip to content

Ship the py.typed marker the Typing :: Typed classifier promises - #241

Open
sunilmehta-si wants to merge 1 commit into
xai-org:mainfrom
sunilmehta-si:ship-py-typed
Open

sunilmehta-si wants to merge 1 commit into
xai-org:mainfrom
sunilmehta-si:ship-py-typed

Conversation

@sunilmehta-si

Copy link
Copy Markdown

Summary

pyproject.toml has declared Typing :: Typed since the first release, but the package has never shipped a py.typed marker (find src -name py.typed is empty, and the built xai_sdk-1.21.0-py3-none-any.whl has none in its RECORD). Type checkers only use a package's inline annotations when that marker is present, so mypy users get:

error: Skipping analyzing "xai_sdk": module is installed, but missing library stubs or py.typed marker  [import-untyped]
note: Revealed type is "Any"

for client.chat.create(...). pyright happens to infer from source by default, which is why this is easy to miss.

This adds the empty src/xai_sdk/py.typed (hatch's packages = ["src/xai_sdk"] already includes non-Python files, so no build change), a test that the installed package carries the marker, and a CHANGELOG entry under Unreleased.

Verification

  • Rebuilt the wheel: py.typed is in it.
  • Fresh venv with the wheel and mypy, a five-line script that calls client.chat.create(...) and reveal_types the result: before, the error above and Any; after, Success: no issues found and Revealed type is "xai_sdk.sync.chat.Chat".
  • ruff format --check, ruff check and the new test pass with the locked environment (uv sync --locked).

Marked as a minor change per the PR template, so no issue was opened first; happy to open one if you prefer.

@deanrie

deanrie commented Oct 27, 2026

Copy link
Copy Markdown

Hey @sunilmehta-si, checked this end to end rather than by reading:

  • The published xai_sdk-1.21.0-py3-none-any.whl from PyPI has no py.typed entry.
  • uv build --wheel on this branch produces one with xai_sdk/py.typed (hatch picks it up through packages = ["src/xai_sdk"], no build config change needed).
  • mypy 1.x on a two-line file, from xai_sdk import Client; reveal_type(Client): against 1.21.0 it reports the missing-stubs error and Revealed type is "Any"; against the wheel from this branch it resolves the full Client signature with no errors.

The test in tests/py_typed_test.py checks the source tree rather than a built wheel, so it would pass even if hatch excluded the file; the wheel check above is what shows the classifier is finally true. Worth a line in the PR body for whoever merges.

@sunilmehta-si

Copy link
Copy Markdown
Author

Thanks for checking it end to end. You're right that the test only looks at the source tree; the wheel is the real check. The PR body's Verification section covers it: the rebuilt wheel contains xai_sdk/py.typed, and mypy resolves Client against it. I'll leave the test as is unless a maintainer wants it to build the wheel.

pyproject.toml has declared "Typing :: Typed" since the first release, but
no py.typed marker was ever added, and hatch only ships what is in the tree.
Without the marker mypy skips the package ("module is installed, but missing
library stubs or py.typed marker") and types every xai_sdk import as Any,
which is exactly what users who trust the classifier run into.

Adds the empty marker, a test that the installed package carries it, and a
changelog entry.
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