Make the package typed: ship py.typed, annotate the public API, type-check in CI - #52
Merged
Merged
Conversation
(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
marked this pull request as ready for review
September 25, 2026 13:48
# Conflicts: # logtail/frame.py # logtail/handler.py
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.typedmarker, mypy refuses to importlogtailin 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.typedmoves from the repository root intologtail/andsetup.pylists it inpackage_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.Anyeverywhere 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.typecheckjob on the latest Python withdisallow_untyped_defs, instead of inside every tox environment.types-requestsandmsgpack-typesjoin the test requirements;types-setuptoolswas dropped since mypy only checkslogtail/.LogtailContext.__exit__returnsNoneinstead 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 abool-typed__exit__that never returnsTrue.Merge order note: this touches
uploader.py,flusher.pyandhandler.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