Repository navigation
fix(types): parameterize Span's context manager and annotate otel span processor - #847
Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit intoOct 5, 2026
Conversation
…n processor `Span` subclassed a bare `contextlib.AbstractContextManager`, so `with start_span(...) as span` typed `span` as Unknown under pyright strict. `start_span`'s `parent` used a bare `dict`, and `add_braintrust_span_processor` left `tracer_provider` and `custom_filter` unannotated, which made both functions partially unknown to consumers that ship strict type checks. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Abhijeet Prasad (AbhiPrasad)
approved these changes
Oct 5, 2026
Abhijeet Prasad (AbhiPrasad)
merged commit Oct 5, 2026
4365035
into
braintrustdata:main
83 checks passed
Member
|
released with https://github.com/braintrustdata/braintrust-sdk-python/releases/tag/py-sdk-v0.44.1. - thanks for the PR Adam Hitchcock (@NorthIsUp) |
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.
Consumers that run pyright in strict mode see
reportUnknown*warnings at everystart_spancall and everywith ... as spanblock, because:Spansubclasses a barecontextlib.AbstractContextManager, so__enter__returns Unknown andspanis untyped inside thewithblock. NowAbstractContextManager["Span"]; both implementations already returnself.start_span'sparent: str | dict | Noneuses a baredict. Nowdict[str, str], which is whatextract_trace_contextbuilds (its return type is narrowed to match).add_braintrust_span_processorleavestracer_providerandcustom_filterunannotated. NowTracerProviderandCallable[[ReadableSpan], bool | None], imported underTYPE_CHECKINGso the optional otel dependency stays optional._MemoryBackgroundLogger.popgets itslist[dict[str, Any]]return type (whatmerge_row_batchreturns).No runtime change. Adds
type_tests/test_span_types.py; itsassert_type(span, Span)fails onmain("expected Span but received Unknown") and passes here under both pyright and mypy. Repo-root pyright on the two touched files goes from 239 to 228 errors and 656 to 625 warnings.Checks run:
nox test_typessteps (pyright + mypy + pytest ontype_tests),pytest src/braintrust/test_logger.py, ruff 0.15.21 check and format.