Skip to content

Make the package typed: ship py.typed, annotate the public API, type-check in CI - #52

Merged
PetrHeinz merged 6 commits into
masterfrom
claude/typed-package
Sep 25, 2026
Merged

PetrHeinz merged 6 commits into
masterfrom
claude/typed-package

Conversation

@PetrHeinz

Copy link
Copy Markdown
Member

Supersedes #29 by @RubenVanEldik, whose two substantive commits are cherry-picked here with credit; its Python version bumps are long since covered by master and were dropped. Two people asked for this on that PR: without a py.typed marker, mypy refuses to import logtail in strictly checked projects.

The first two commits are the original PR rebased onto master. The third commit makes it actually work and finishes the job:

  • py.typed moves from the repository root into logtail/ and setup.py lists it in package_data. At the root it was never packaged, so an installed 0.4.1 with that PR merged would still have been untyped. Verified on the built wheel and sdist.
  • Every function in the package is annotated. Marking a package typed without annotations turns the old "missing stubs" error into Any everywhere and, under --strict, into "call to untyped function" errors at each call site, so the public surface (LogtailHandler, LogtailContext, LogtailFormatter, logtail.rq.Worker) and the internals now carry real signatures.
  • mypy runs as its own typecheck job on the latest Python with disallow_untyped_defs, instead of inside every tox environment. types-requests and msgpack-types join the test requirements; types-setuptools was dropped since mypy only checks logtail/.
  • LogtailContext.__exit__ returns None instead of the context object. It only ever returned that when there was no exception to swallow, so nothing changes at runtime, and mypy rightly refuses a bool-typed __exit__ that never returns True.

Merge order note: this touches uploader.py, flusher.py and handler.py, so it should go in after #49 and #51 and will need a trivial rebase then. Making the package typed is a visible change for downstream type checkers, so it belongs in a minor release.

🤖 Generated with Claude Code

Ruben van Eldik and others added 5 commits September 25, 2026 15:05
(cherry picked from commit f113e8f)
(cherry picked from commit 20fe01c)
…eck in CI

py.typed only counts when it is installed next to the package's modules, so it moves into logtail/ and setup.py packages it. Every function in the package is annotated and mypy runs as its own CI job with disallow_untyped_defs, so strict type checkers see real signatures instead of untyped calls. LogtailContext.__exit__ now returns None instead of the context object; it only ever returned that when there was no exception to swallow, so nothing changes at runtime.

Co-Authored-By: Ruben van Eldik <vaneldik@emmettgreen.nl>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
# Conflicts:
#	logtail/flusher.py
#	logtail/handler.py
#	logtail/uploader.py
logging.Handler takes a level name as well as a number, and requests accepts a (connect, read) tuple or None as the timeout, so the annotations must not reject either.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@PetrHeinz
PetrHeinz marked this pull request as ready for review September 25, 2026 13:48
# Conflicts:
#	logtail/frame.py
#	logtail/handler.py
@PetrHeinz
PetrHeinz merged commit 3c5e719 into master Sep 25, 2026
17 checks passed
@PetrHeinz
PetrHeinz deleted the claude/typed-package branch September 25, 2026 14:11
@PetrHeinz PetrHeinz mentioned this pull request Sep 25, 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