Skip to content

Export the public API explicitly and drop a context when its block raises - #55

Merged
PetrHeinz merged 2 commits into
masterfrom
claude/typed-exports-context-exit
Sep 25, 2026
Merged

PetrHeinz merged 2 commits into
masterfrom
claude/typed-exports-context-exit

Conversation

@PetrHeinz

@PetrHeinz PetrHeinz commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Two fixes found in an end-to-end run of 0.5.0, meant for a 0.5.1 patch release.

  • Explicit exports. Now that the package ships py.typed, type checkers take logtail/__init__.py at its word. It imports LogtailHandler, LogtailFormatter, LogtailContext and DEFAULT_CONTEXT without __all__, so the usual from logtail import LogtailHandler fails with "does not explicitly export" under mypy --strict, and with reportPrivateImportUsage in Pyright's default mode, which is what Pylance users see. Plain mypy is unaffected. 0.4.3 had no py.typed, so this is new in 0.5.0. The fix adds __all__.
  • Leaving a context by exception. LogtailContext.__exit__ removed the context only when the block exited normally. After an exception inside with logtail.context(...), that context was attached to every later record in the process. It is now removed either way. The exception still propagates, as test_does_not_suppress_exceptions checks. 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=silent on tests/typecheck/public_api.py, a file that imports and calls the API the way an application would. --follow-imports=silent hides errors inside logtail itself, just as they are hidden for an installed package. tests/test_helpers.py gets 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

PetrHeinz and others added 2 commits September 25, 2026 16:26
…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>
@PetrHeinz
PetrHeinz marked this pull request as ready for review September 25, 2026 14:51
@PetrHeinz
PetrHeinz merged commit 7a70947 into master Sep 25, 2026
18 checks passed
@PetrHeinz
PetrHeinz deleted the claude/typed-exports-context-exit branch September 25, 2026 14:51
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