From 7373b21779affe63d7f5e24f937296dc76e34db2 Mon Sep 17 00:00:00 2001 From: William Schmitt Date: Mon, 16 Nov 2026 13:19:10 -0800 Subject: [PATCH] fix(types): type-check _TYPE_ALIAS_TYPES on Python 3.12+ `_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 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 --- scripts/lint | 2 ++ src/browserbase/_utils/_typing.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/lint b/scripts/lint index 941f8c21..6ccdd706 100755 --- a/scripts/lint +++ b/scripts/lint @@ -14,9 +14,11 @@ fi echo "==> Running pyright" uv run pyright -p . +uv run pyright -p . --pythonversion 3.12 echo "==> Running mypy" uv run mypy . +uv run mypy . --python-version 3.12 echo "==> Making sure it imports" uv run python -c 'import browserbase' diff --git a/src/browserbase/_utils/_typing.py b/src/browserbase/_utils/_typing.py index 193109f3..d8411fc7 100644 --- a/src/browserbase/_utils/_typing.py +++ b/src/browserbase/_utils/_typing.py @@ -51,9 +51,10 @@ def is_typevar(typ: type) -> bool: return type(typ) == TypeVar # type: ignore -_TYPE_ALIAS_TYPES: tuple[type[typing_extensions.TypeAliasType], ...] = (typing_extensions.TypeAliasType,) if sys.version_info >= (3, 12): - _TYPE_ALIAS_TYPES = (*_TYPE_ALIAS_TYPES, typing.TypeAliasType) + _TYPE_ALIAS_TYPES = (typing_extensions.TypeAliasType, typing.TypeAliasType) +else: + _TYPE_ALIAS_TYPES = (typing_extensions.TypeAliasType,) def is_type_alias_type(tp: Any, /) -> TypeIs[typing_extensions.TypeAliasType]: