Export the public API explicitly and drop a context when its block raises - #55
Merged
Merged
Conversation
…eption - tests/typecheck/public_api.py imports LogtailHandler, LogtailFormatter, LogtailContext and DEFAULT_CONTEXT from `logtail` as applications do; the typecheck job now checks it with `mypy --strict`, which fails because `logtail/__init__.py` does not re-export them explicitly. - test_exception_leaves_the_context: a context whose `with` block raises is still applied afterwards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ises - `__all__` in logtail/__init__.py, so `from logtail import LogtailHandler` passes `mypy --strict` and Pyright now that the package ships py.typed. - LogtailContext.__exit__ pops the context whether or not the block raised; the exception still propagates since __exit__ returns None. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Two fixes found in an end-to-end run of 0.5.0, meant for a 0.5.1 patch release.
py.typed, type checkers takelogtail/__init__.pyat its word. It importsLogtailHandler,LogtailFormatter,LogtailContextandDEFAULT_CONTEXTwithout__all__, so the usualfrom logtail import LogtailHandlerfails with "does not explicitly export" undermypy --strict, and withreportPrivateImportUsagein Pyright's default mode, which is what Pylance users see. Plain mypy is unaffected. 0.4.3 had nopy.typed, so this is new in 0.5.0. The fix adds__all__.LogtailContext.__exit__removed the context only when the block exited normally. After an exception insidewith logtail.context(...), that context was attached to every later record in the process. It is now removed either way. The exception still propagates, astest_does_not_suppress_exceptionschecks. This bug predates 0.5.0.The first commit adds only the tests and is expected to fail on CI. A new step in the typecheck job runs
mypy --strict --follow-imports=silentontests/typecheck/public_api.py, a file that imports and calls the API the way an application would.--follow-imports=silenthides errors insidelogtailitself, just as they are hidden for an installed package.tests/test_helpers.pygets the context case. The second commit is the fix.Pyright isn't in CI because it needs Node. I checked it locally against installed wheels, outside the repo so the local source is not picked up: released 0.5.0 gives 4 errors on that file in Pyright and in
mypy --strict, this branch gives 0 in both.🤖 Generated with Claude Code