Repository navigation
[CB-0] [sdk-superfan] Fix mypy and pyright on Python 3.12 TypeAliasType branch - #217
Open
spicysouvlaki wants to merge 1 commit into
Open
spicysouvlaki wants to merge 1 commit into
spicysouvlaki wants to merge 1 commit into
Conversation
`_TYPE_ALIAS_TYPES` was annotated `tuple[type[typing_extensions.TypeAliasType], ...]` and then extended with the stdlib `typing.TypeAliasType` under `sys.version_info >= (3, 12)`. On 3.12+ these are distinct classes, so: - mypy 1.17: `Argument 2 to <tuple> has incompatible type "type[typing.TypeAliasType]"; expected "type[typing_extensions.TypeAliasType]"` - pyright 1.1.399 strict: reportConstantRedefinition plus the same assignability error. CI never saw it because lint runs on `.python-version` (3.9), where both checkers treat the 3.12 branch as unreachable. Reproduced from the 3.9 env with `mypy --python-version 3.12 .` and `pyright --pythonversion 3.12`. Fix: pick the tuple per version branch with no shared annotation, so each checker infers the concrete tuple for the target it evaluates. Narrowing is unchanged: it comes from `is_type_alias_type`'s `TypeIs` return type, not the tuple's declared type. Guard: scripts/lint now also runs pyright and mypy with a 3.12 target. Both fail on origin/main and pass with this change; 3.9 and 3.13 targets pass too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
spicysouvlaki
marked this pull request as ready for review
November 16, 2026 21:46
This branch has not been deployed
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.
What happened
#178:
mypy srcon Python 3.12 fails withsrc/browserbase/_utils/_typing.py:56: error: Argument 2 to <tuple> has incompatible type "type[typing.TypeAliasType]"; expected "type[typing_extensions.TypeAliasType]" [arg-type]Why
src/browserbase/_utils/_typing.py:54-56annotates the tuple with thetyping_extensionsclass, then appends the distinct stdlib class on 3.12+. Pyright strict also fails there (reportConstantRedefinition). CI lints only on 3.9, where that branch is unreachable.Fix
Build the tuple in an
if/elseonsys.version_infowith no shared annotation.TypeIsonis_type_alias_typestill drives narrowing.Tests
scripts/lintnow also runs pyright and mypy with a 3.12 target../scripts/lintfails (pyright 3.12: 2 errors; mypy 3.12: 1 error). After: passes, 0 errors on 3.9 / 3.12 / 3.13 targets for both../scripts/test(steady mock): 3.9 and 3.14, pydantic v1 + v2, all pass.Risk and rollout
Touches the generated
_utils/_typing.pyandscripts/lint. Stainless seals both, so expect a possible merge conflict if the template changes those lines. No runtime behavior change.Fixes #178
🤖 Generated with Claude Code