Skip to content

Conversation

dcreager
Copy link
Member

@dcreager dcreager commented Aug 7, 2025

This PR creates separate Rust types for bound and unbound type variables, as proposed in astral-sh/ty#926.

Closes astral-sh/ty#926

@dcreager
Copy link
Member Author

dcreager commented Aug 7, 2025

@carljm and I concurrently realized that we didn't need a new Type variant for unbound typevars, since we can use KnownInstanceType::TypeVar for that. A wrinkle is that at first I thought that unbound typevars should not be allowed in type expressions. But that breaks default values for legacy typevars:

from typing import Generic, TypeVar

T = TypeVar("T")
U = TypeVar("U", default=T)

The use of T is (correctly) unbound, but also appears in a type form position, so we do need to allow KnownInstanceType::TypeVar in type expressions.

I feel like perhaps this calls into question the strategy of binding typevars in infer_place_load in the first place; it seems like maybe we should really only ever be binding them in in_type_expression?

This was a good suggestion, which I've implemented.

Copy link
Contributor

github-actions bot commented Aug 7, 2025

mypy_primer results

Changes were detected when running on open source projects
bidict (https://github.com/jab/bidict)
- bidict/_typing.py:40:39: error[non-subscriptable] Cannot subscript object of type `<class 'Iterable[tuple[KT, VT]]'>` with no `__class_getitem__` method
+ bidict/_typing.py:40:39: error[non-subscriptable] Cannot subscript object of type `<class 'Iterable[tuple[typing.TypeVar("KT"), typing.TypeVar("VT")]]'>` with no `__class_getitem__` method

Expression (https://github.com/cognitedata/Expression)
+ expression/collections/maptree.py:47:18: error[invalid-argument-type] Argument to class `MapTreeLeaf` is incorrect: Expected `SupportsLessThan`, found `typing.TypeVar("Key", bound=SupportsLessThan)`
- expression/extra/result/catch.py:50:16: error[invalid-return-type] Return type does not match returned value: expected `((...) -> _TSource@catch, /) -> ((...) -> Result[_TSource@catch, _TError@catch]) | Result[_TSource@catch, _TError@catch]`, found `(...) -> Result[_TSource@catch, _TError@catch]`
- expression/extra/result/catch.py:50:26: error[invalid-argument-type] Argument to function `decorator` is incorrect: Expected `(...) -> _TSource@catch`, found `(...) -> _TSource@catch`
- expression/extra/result/catch.py:52:12: error[invalid-return-type] Return type does not match returned value: expected `((...) -> _TSource@catch, /) -> ((...) -> Result[_TSource@catch, _TError@catch]) | Result[_TSource@catch, _TError@catch]`, found `def decorator(fn: (...) -> _TSource@catch) -> (...) -> Result[_TSource@catch, _TError@catch]`
- Found 228 diagnostics
+ Found 226 diagnostics

black (https://github.com/psf/black)
+ src/black/rusty.py:28:23: error[invalid-argument-type] Argument to class `Err` is incorrect: Expected `Exception`, found `typing.TypeVar("E", bound=Exception)`
- Found 63 diagnostics
+ Found 64 diagnostics

anyio (https://github.com/agronholm/anyio)
- src/anyio/from_thread.py:291:16: error[invalid-return-type] Return type does not match returned value: expected `T_Retval@call`, found `T_Retval@call`
- Found 224 diagnostics
+ Found 223 diagnostics

werkzeug (https://github.com/pallets/werkzeug)
- src/werkzeug/datastructures/mixins.py:238:28: error[invalid-argument-type] Argument is incorrect: Expected `Self`, found `UpdateDictMixin[Any, Any]`
+ src/werkzeug/datastructures/mixins.py:238:28: error[invalid-argument-type] Argument is incorrect: Expected `typing.Self`, found `UpdateDictMixin[Any, Any]`
- src/werkzeug/datastructures/mixins.py:262:28: error[invalid-argument-type] Argument is incorrect: Expected `Self`, found `Self@setdefault`
+ src/werkzeug/datastructures/mixins.py:262:28: error[invalid-argument-type] Argument is incorrect: Expected `typing.Self`, found `Self@setdefault`
- src/werkzeug/datastructures/mixins.py:282:28: error[invalid-argument-type] Argument is incorrect: Expected `Self`, found `Self@pop`
+ src/werkzeug/datastructures/mixins.py:282:28: error[invalid-argument-type] Argument is incorrect: Expected `typing.Self`, found `Self@pop`

discord.py (https://github.com/Rapptz/discord.py)
- discord/app_commands/commands.py:111:64: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:111:64: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/app_commands/commands.py:113:61: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:113:61: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/app_commands/commands.py:116:52: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:116:52: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/app_commands/commands.py:122:62: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:122:62: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/app_commands/commands.py:123:54: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:123:54: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/app_commands/commands.py:132:48: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:132:48: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/app_commands/commands.py:133:46: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:133:46: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/app_commands/commands.py:134:49: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:134:49: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/app_commands/commands.py:135:61: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:135:61: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/app_commands/commands.py:139:53: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:139:53: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:139:63: error[invalid-argument-type] Argument to class `Choice` is incorrect: Expected `str | int | float`, found `typing.TypeVar("ChoiceT", str, int, int | float, str | int | float)`
- discord/app_commands/commands.py:140:45: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:140:45: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
+ discord/app_commands/commands.py:140:55: error[invalid-argument-type] Argument to class `Choice` is incorrect: Expected `str | int | float`, found `typing.TypeVar("ChoiceT", str, int, int | float, str | int | float)`
- discord/app_commands/commands.py:2537:16: error[invalid-return-type] Return type does not match returned value: expected `T@guild_only | ((T@guild_only, /) -> T@guild_only)`, found `def inner(f: T@guild_only) -> T@guild_only`
- discord/app_commands/commands.py:2539:16: error[invalid-return-type] Return type does not match returned value: expected `T@guild_only | ((T@guild_only, /) -> T@guild_only)`, found `T@guild_only`
- discord/app_commands/commands.py:2539:22: error[invalid-argument-type] Argument to function `inner` is incorrect: Expected `T@guild_only`, found `T@guild_only & ~None`
- discord/app_commands/commands.py:2594:16: error[invalid-return-type] Return type does not match returned value: expected `T@private_channel_only | ((T@private_channel_only, /) -> T@private_channel_only)`, found `def inner(f: T@private_channel_only) -> T@private_channel_only`
- discord/app_commands/commands.py:2596:16: error[invalid-return-type] Return type does not match returned value: expected `T@private_channel_only | ((T@private_channel_only, /) -> T@private_channel_only)`, found `T@private_channel_only`
- discord/app_commands/commands.py:2596:22: error[invalid-argument-type] Argument to function `inner` is incorrect: Expected `T@private_channel_only`, found `T@private_channel_only & ~None`
- discord/app_commands/commands.py:2649:16: error[invalid-return-type] Return type does not match returned value: expected `T@dm_only | ((T@dm_only, /) -> T@dm_only)`, found `def inner(f: T@dm_only) -> T@dm_only`
- discord/app_commands/commands.py:2651:16: error[invalid-return-type] Return type does not match returned value: expected `T@dm_only | ((T@dm_only, /) -> T@dm_only)`, found `T@dm_only`
- discord/app_commands/commands.py:2651:22: error[invalid-argument-type] Argument to function `inner` is incorrect: Expected `T@dm_only`, found `T@dm_only & ~None`
- discord/app_commands/commands.py:2744:16: error[invalid-return-type] Return type does not match returned value: expected `T@guild_install | ((T@guild_install, /) -> T@guild_install)`, found `def inner(f: T@guild_install) -> T@guild_install`
- discord/app_commands/commands.py:2746:16: error[invalid-return-type] Return type does not match returned value: expected `T@guild_install | ((T@guild_install, /) -> T@guild_install)`, found `T@guild_install`
- discord/app_commands/commands.py:2746:22: error[invalid-argument-type] Argument to function `inner` is incorrect: Expected `T@guild_install`, found `T@guild_install & ~None`
- discord/app_commands/commands.py:2795:16: error[invalid-return-type] Return type does not match returned value: expected `T@user_install | ((T@user_install, /) -> T@user_install)`, found `def inner(f: T@user_install) -> T@user_install`
- discord/app_commands/commands.py:2797:16: error[invalid-return-type] Return type does not match returned value: expected `T@user_install | ((T@user_install, /) -> T@user_install)`, found `T@user_install`
- discord/app_commands/commands.py:2797:22: error[invalid-argument-type] Argument to function `inner` is incorrect: Expected `T@user_install`, found `T@user_install & ~None`
+ discord/app_commands/tree.py:76:10: error[invalid-argument-type] Argument to class `Interaction` is incorrect: Expected `Client`, found `typing.TypeVar("ClientT", bound=Client, default=Client)`
+ discord/client.py:308:27: error[invalid-argument-type] Argument to class `ConnectionState` is incorrect: Expected `Client`, found `typing.Self`
- discord/ext/commands/_types.py:47:26: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/ext/commands/_types.py:47:26: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/ext/commands/_types.py:48:22: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/ext/commands/_types.py:48:22: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/ext/commands/_types.py:53:45: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/ext/commands/_types.py:53:45: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/ext/commands/_types.py:53:80: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/ext/commands/_types.py:53:80: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/ext/commands/_types.py:54:62: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/ext/commands/_types.py:54:62: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/ext/commands/_types.py:54:113: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/ext/commands/_types.py:54:113: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/ext/commands/hybrid.py:85:50: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/ext/commands/hybrid.py:85:50: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
- discord/ext/commands/hybrid.py:86:44: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, T]'>` with no `__class_getitem__` method
+ discord/ext/commands/hybrid.py:86:44: error[non-subscriptable] Cannot subscript object of type `<class 'Coroutine[Any, Any, typing.TypeVar("T")]'>` with no `__class_getitem__` method
+ discord/ui/modal.py:102:50: error[invalid-argument-type] Argument to class `Item` is incorrect: Expected `View`, found `typing.Self`
+ discord/ui/view.py:191:30: error[invalid-argument-type] Argument to class `Item` is incorrect: Expected `View`, found `typing.Self`
+ discord/ui/view.py:587:74: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
+ discord/ui/view.py:606:81: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 530 diagnostics
+ Found 523 diagnostics

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- bson/__init__.py:1097:12: error[invalid-return-type] Return type does not match returned value: expected `dict[str, Any] | _DocumentType@decode`, found `dict[str, Any] | _DocumentType@decode`
+ pymongo/asynchronous/collection.py:104:5: error[invalid-argument-type] Argument to class `InsertOne` is incorrect: Expected `Mapping[str, Any]`, found `typing.TypeVar("_DocumentType", bound=Mapping[str, Any])`
+ pymongo/asynchronous/collection.py:107:5: error[invalid-argument-type] Argument to class `ReplaceOne` is incorrect: Expected `Mapping[str, Any]`, found `typing.TypeVar("_DocumentType", bound=Mapping[str, Any])`
+ pymongo/synchronous/collection.py:103:5: error[invalid-argument-type] Argument to class `InsertOne` is incorrect: Expected `Mapping[str, Any]`, found `typing.TypeVar("_DocumentType", bound=Mapping[str, Any])`
+ pymongo/synchronous/collection.py:106:5: error[invalid-argument-type] Argument to class `ReplaceOne` is incorrect: Expected `Mapping[str, Any]`, found `typing.TypeVar("_DocumentType", bound=Mapping[str, Any])`
- Found 508 diagnostics
+ Found 511 diagnostics

strawberry (https://github.com/strawberry-graphql/strawberry)
- strawberry/types/enum.py:236:16: error[invalid-return-type] Return type does not match returned value: expected `EnumType@enum | ((EnumType@enum, /) -> EnumType@enum)`, found `def wrap(cls: EnumType@enum) -> EnumType@enum`
- strawberry/types/enum.py:238:12: error[invalid-return-type] Return type does not match returned value: expected `EnumType@enum | ((EnumType@enum, /) -> EnumType@enum)`, found `EnumType@enum`
- strawberry/types/enum.py:238:17: error[invalid-argument-type] Argument to function `wrap` is incorrect: Expected `EnumType@enum`, found `EnumType@enum & ~AlwaysFalsy`
- strawberry/types/object_type.py:321:16: error[invalid-return-type] Return type does not match returned value: expected `T@type | ((T@type, /) -> T@type)`, found `def wrap(cls: T@type) -> T@type`
- Found 381 diagnostics
+ Found 377 diagnostics

pydantic (https://github.com/pydantic/pydantic)
- pydantic/config.py:1210:12: error[invalid-return-type] Return type does not match returned value: expected `(_TypeT@with_config, /) -> _TypeT@with_config`, found `def inner(class_: _TypeT@with_config, /) -> _TypeT@with_config`
- pydantic/validate_call_decorator.py:116:16: error[invalid-return-type] Return type does not match returned value: expected `AnyCallableT@validate_call | ((AnyCallableT@validate_call, /) -> AnyCallableT@validate_call)`, found `def validate(function: AnyCallableT@validate_call) -> AnyCallableT@validate_call`
- Found 759 diagnostics
+ Found 757 diagnostics

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_make_custom_builds.py:351:12: error[invalid-return-type] Return type does not match returned value: expected `FullBuilds[T@make_custom_builds_fn] | PBuilds[T@make_custom_builds_fn] | StdBuilds[T@make_custom_builds_fn]`, found `FullBuilds[T@make_custom_builds_fn] | PBuilds[T@make_custom_builds_fn] | StdBuilds[T@make_custom_builds_fn]`
- src/hydra_zen/wrapper/_implementations.py:1638:20: error[invalid-return-type] Return type does not match returned value: expected `F@__call__ | Self@__call__`, found `F | Self@__call__`
- Found 565 diagnostics
+ Found 563 diagnostics

schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/core/result.py:27:23: error[invalid-argument-type] Argument to class `Err` is incorrect: Expected `Exception`, found `typing.TypeVar("E", bound=Exception)`
- Found 278 diagnostics
+ Found 279 diagnostics

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/raises.py:1004:33: error[invalid-argument-type] Argument to class `RaisesExc` is incorrect: Expected `BaseException`, found `typing.TypeVar("BaseExcT_co", bound=BaseException)`
- Found 470 diagnostics
+ Found 471 diagnostics

django-stubs (https://github.com/typeddjango/django-stubs)
+ django-stubs/contrib/admin/options.pyi:148:66: error[invalid-argument-type] Argument to class `QuerySet` is incorrect: Expected `Model`, found `typing.TypeVar("_ModelT", bound=Model)`
+ django-stubs/contrib/auth/models.pyi:106:23: error[invalid-argument-type] Argument to class `UserManager` is incorrect: Expected `AbstractBaseUser`, found `typing.Self`
+ django-stubs/contrib/gis/db/backends/oracle/models.pyi:12:23: error[invalid-argument-type] Argument to class `Manager` is incorrect: Expected `Model`, found `typing.Self`
+ django-stubs/contrib/gis/db/backends/oracle/models.pyi:26:23: error[invalid-argument-type] Argument to class `Manager` is incorrect: Expected `Model`, found `typing.Self`
+ django-stubs/contrib/gis/db/backends/postgis/models.pyi:15:23: error[invalid-argument-type] Argument to class `Manager` is incorrect: Expected `Model`, found `typing.Self`
+ django-stubs/contrib/gis/db/backends/postgis/models.pyi:28:23: error[invalid-argument-type] Argument to class `Manager` is incorrect: Expected `Model`, found `typing.Self`
+ django-stubs/contrib/gis/db/backends/spatialite/models.pyi:14:23: error[invalid-argument-type] Argument to class `Manager` is incorrect: Expected `Model`, found `typing.Self`
+ django-stubs/contrib/gis/db/backends/spatialite/models.pyi:28:23: error[invalid-argument-type] Argument to class `Manager` is incorrect: Expected `Model`, found `typing.Self`
+ django-stubs/db/migrations/recorder.pyi:14:27: error[invalid-argument-type] Argument to class `Manager` is incorrect: Expected `Model`, found `typing.Self`
+ django-stubs/db/models/base.pyi:45:23: error[invalid-argument-type] Argument to class `Manager` is incorrect: Expected `Model`, found `typing.Self`
+ django-stubs/db/models/base.pyi:47:21: error[invalid-argument-type] Argument to class `Options` is incorrect: Expected `Model`, found `typing.Self`
+ ext/django_stubs_ext/annotations.py:18:33: error[invalid-argument-type] Argument to class `Annotations` is incorrect: Expected `Mapping[str, Any]`, found `typing.TypeVar("_Annotations", bound=Mapping[str, Any])`
- mypy_django_plugin/django/context.py:419:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[Field[Any, Any] | ForeignObjectRel, type[Model]]`, found `tuple[None | Field[Unknown, Unknown] | ForeignObjectRel | GenericForeignKey | Unknown, type[Model] | Unknown]`
+ mypy_django_plugin/django/context.py:419:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[Field[Any, Any] | ForeignObjectRel, type[Model]]`, found `tuple[None | Unknown, type[Model] | Unknown]`
- Found 430 diagnostics
+ Found 442 diagnostics

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/test/unit/test_type_clinic.py:2878:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `typing.TypeVar("T", bound=generic[Any])`
+ static_frame/test/unit/test_type_clinic.py:2879:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `typing.TypeVar("T", bound=generic[Any])`
+ static_frame/test/unit/test_type_clinic.py:2902:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `typing.TypeVar("T", signedinteger[_64Bit], float64)`
+ static_frame/test/unit/test_type_clinic.py:2903:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `typing.TypeVar("T", signedinteger[_64Bit], float64)`
+ static_frame/test/unit/test_type_clinic.py:2922:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `typing.TypeVar("T", signedinteger[_64Bit], float64)`
+ static_frame/test/unit/test_type_clinic.py:2923:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `typing.TypeVar("T", signedinteger[_64Bit], float64)`
- static_frame/test/unit/test_type_clinic.py:2947:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `T`
+ static_frame/test/unit/test_type_clinic.py:2947:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `typing.TypeVar("T")`
- static_frame/test/unit/test_type_clinic.py:2948:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `T`
+ static_frame/test/unit/test_type_clinic.py:2948:9: error[invalid-argument-type] Argument to class `Index` is incorrect: Expected `generic[Any]`, found `typing.TypeVar("T")`
- Found 1771 diagnostics
+ Found 1777 diagnostics

streamlit (https://github.com/streamlit/streamlit)
- lib/streamlit/elements/dialog_decorator.py:293:16: error[invalid-return-type] Return type does not match returned value: expected `F@dialog_decorator | ((F@dialog_decorator, /) -> F@dialog_decorator)`, found `def wrapper(f: F@dialog_decorator) -> F@dialog_decorator`
- lib/streamlit/elements/dialog_decorator.py:295:5: error[invalid-assignment] Object of type `F@dialog_decorator & ~str` is not assignable to `F@dialog_decorator`
- lib/streamlit/elements/dialog_decorator.py:334:16: error[invalid-return-type] Return type does not match returned value: expected `F@experimental_dialog_decorator | ((F@experimental_dialog_decorator, /) -> F@experimental_dialog_decorator)`, found `def wrapper(f: F@experimental_dialog_decorator) -> F@experimental_dialog_decorator`
- lib/streamlit/elements/dialog_decorator.py:336:5: error[invalid-assignment] Object of type `F@experimental_dialog_decorator & ~str` is not assignable to `F@experimental_dialog_decorator`
- lib/streamlit/runtime/metrics_util.py:393:16: error[invalid-return-type] Return type does not match returned value: expected `((F@gather_metrics, /) -> F@gather_metrics) | F@gather_metrics`, found `def wrapper(f: F@gather_metrics) -> F@gather_metrics`
- Found 148 diagnostics
+ Found 143 diagnostics

meson (https://github.com/mesonbuild/meson)
- mesonbuild/cargo/builder.py:33:72: error[invalid-argument-type] Argument is incorrect: Argument type `TV_TokenTypes` does not satisfy constraints of type variable `TV_TokenTypes`
+ mesonbuild/cargo/builder.py:33:72: error[invalid-argument-type] Argument is incorrect: Argument type `TV_TokenTypes@_token` does not satisfy constraints of type variable `TV_TokenTypes`

prefect (https://github.com/PrefectHQ/prefect)
- src/integrations/prefect-dask/prefect_dask/task_runners.py:448:16: error[invalid-return-type] Return type does not match returned value: expected `PrefectDaskFuture[R@submit]`, found `PrefectDaskFuture[R@submit]`
- src/prefect/utilities/asyncutils.py:188:24: error[invalid-return-type] Return type does not match returned value: expected `R@run_coro_as_sync | None`, found `R@run_coro_as_sync`
- src/prefect/utilities/collections.py:395:36: error[invalid-argument-type] Argument is incorrect: Expected `dict[str, VT@visit_collection]`, found `dict[str, VT@visit_collection]`
- src/prefect/utilities/collections.py:463:13: error[invalid-assignment] Method `__setitem__` of type `bound method dict[str, VT@visit_collection].__setitem__(key: str, value: VT@visit_collection, /) -> None` cannot be called with a key of type `Literal["annotation"]` and a value of type `VT@visit_collection` on object of type `dict[str, VT@visit_collection]`
- src/prefect/utilities/collections.py:662:16: error[invalid-return-type] Return type does not match returned value: expected `VT@get_from_dict | R@get_from_dict | None`, found `VT@get_from_dict`
- src/prefect/utilities/templating.py:161:16: error[invalid-return-type] Return type does not match returned value: expected `T@apply_values | type[NotSet]`, found `T@apply_values`
- src/prefect/utilities/templating.py:218:16: error[invalid-return-type] Return type does not match returned value: expected `T@apply_values | type[NotSet]`, found `T@apply_values`
- src/prefect/utilities/templating.py:230:16: error[invalid-return-type] Return type does not match returned value: expected `T@apply_values | type[NotSet]`, found `T@apply_values`
- Found 2965 diagnostics
+ Found 2957 diagnostics

zulip (https://github.com/zulip/zulip)
- analytics/lib/counts.py:83:12: error[unresolved-attribute] Type `Self` has no attribute `state`
- analytics/lib/counts.py:84:20: error[unresolved-attribute] Type `Self` has no attribute `end_time`
- analytics/lib/counts.py:85:16: error[unresolved-attribute] Type `Self` has no attribute `end_time`
- analytics/lib/counts.py:164:10: error[unresolved-attribute] Type `Self` has no attribute `state`
- analytics/lib/counts.py:165:56: error[unresolved-attribute] Type `Self` has no attribute `end_time`
- analytics/lib/counts.py:166:40: error[unresolved-attribute] Type `Self` has no attribute `end_time`
- analytics/lib/counts.py:167:28: error[unresolved-attribute] Type `Self` has no attribute `end_time`
- analytics/lib/counts.py:168:30: error[invalid-argument-type] Argument to function `do_update_fill_state` is incorrect: Expected `FillState`, found `Self`
- analytics/lib/counts.py:170:10: error[unresolved-attribute] Type `Self` has no attribute `state`
- analytics/lib/counts.py:171:28: error[unresolved-attribute] Type `Self` has no attribute `end_time`
- analytics/lib/counts.py:173:68: error[unresolved-attribute] Type `Self` has no attribute `state`
- analytics/lib/counts.py:189:30: error[invalid-argument-type] Argument to function `do_update_fill_state` is incorrect: Expected `FillState`, found `Self`
- analytics/lib/counts.py:191:30: error[invalid-argument-type] Argument to function `do_update_fill_state` is incorrect: Expected `FillState`, found `Self`
- analytics/management/commands/populate_analytics_db.py:124:54: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:125:9: error[unresolved-attribute] Unresolved attribute `recipient` on type `Self`.
- analytics/management/commands/populate_analytics_db.py:131:13: error[invalid-argument-type] Argument to function `create_stream_subscription` is incorrect: Expected `Recipient`, found `Self`
- analytics/management/commands/populate_analytics_db.py:132:13: error[invalid-argument-type] Argument to function `create_stream_subscription` is incorrect: Expected `Stream`, found `Self`
- analytics/management/commands/populate_analytics_db.py:292:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:293:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:297:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:298:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:299:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:300:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:301:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:302:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:303:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:304:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:305:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:306:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:310:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:311:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:312:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:313:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:314:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:315:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:316:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:317:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:318:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/management/commands/populate_analytics_db.py:319:13: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_counts.py:163:54: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_counts.py:164:9: error[unresolved-attribute] Unresolved attribute `recipient` on type `Self`.
- analytics/tests/test_counts.py:166:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[Stream, Recipient]`, found `tuple[Self, Self]`
- analytics/tests/test_counts.py:177:21: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_counts.py:179:9: error[unresolved-attribute] Unresolved attribute `recipient` on type `Self`.
- analytics/tests/test_counts.py:181:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[DirectMessageGroup, Recipient]`, found `tuple[Self, Self]`
- analytics/tests/test_counts.py:199:16: error[invalid-return-type] Return type does not match returned value: expected `Message`, found `Self`
- analytics/tests/test_counts.py:209:16: error[invalid-return-type] Return type does not match returned value: expected `Attachment`, found `Self`
- analytics/tests/test_counts.py:287:26: error[unresolved-attribute] Type `Self` has no attribute `end_time`
- analytics/tests/test_counts.py:288:26: error[unresolved-attribute] Type `Self` has no attribute `state`
- analytics/tests/test_counts.py:870:26: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_counts.py:918:26: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_counts.py:1257:9: error[unresolved-attribute] Unresolved attribute `state` on type `Self`.
- analytics/tests/test_counts.py:1263:9: error[unresolved-attribute] Unresolved attribute `property` on type `Self`.
- analytics/tests/test_counts.py:1735:13: error[invalid-argument-type] Argument to function `do_revoke_user_invite` is incorrect: Expected `PreregistrationUser`, found `Self | None`
- analytics/tests/test_counts.py:1741:39: error[invalid-argument-type] Argument to function `do_send_user_invite_email` is incorrect: Expected `PreregistrationUser`, found `Self | None`
- analytics/tests/test_counts.py:2150:34: error[unresolved-attribute] Type `Self` has no attribute `remote_id`
- analytics/tests/test_stats_views.py:223:18: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_stats_views.py:223:35: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_stats_views.py:223:52: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_stats_views.py:224:18: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_stats_views.py:224:35: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/tests/test_stats_views.py:526:9: error[unresolved-attribute] Unresolved attribute `end_time` on type `Self`.
- analytics/views/stats.py:138:20: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/views/stats.py:140:52: error[unresolved-attribute] Type `Self` has no attribute `hostname`
- analytics/views/stats.py:243:20: error[unresolved-attribute] Type `Self` has no attribute `id`
- analytics/views/stats.py:245:38: error[unresolved-attribute] Type `Self` has no attribute `hostname`
- confirmation/models.py:114:8: error[unresolved-attribute] Type `Self` has no attribute `expiry_date`
- confirmation/models.py:114:66: error[unresolved-attribute] Type `Self` has no attribute `expiry_date`
- confirmation/models.py:117:11: error[unresolved-attribute] Type `Self` has no attribute `content_object`
- confirmation/models.py:132:16: error[unresolved-attribute] Type `Self` has no attribute `type`
- confirmation/models.py:172:12: error[invalid-return-type] Return type does not match returned value: expected `Confirmation`, found `Self`
- corporate/lib/decorator.py:118:40: error[unresolved-attribute] Type `Self` has no attribute `host`
- corporate/lib/remote_billing_util.py:129:9: error[unresolved-attribute] Type `Self` has no attribute `registration_deactivated`
- corporate/lib/remote_billing_util.py:130:12: error[unresolved-attribute] Type `Self` has no attribute `realm_deactivated`
- corporate/lib/remote_billing_util.py:131:12: error[unresolved-attribute] Type `Self` has no attribute `server`
- corporate/lib/remote_billing_util.py:148:12: error[invalid-return-type] Return type does not match returned value: expected `tuple[RemoteRealm, RemoteRealmBillingUser]`, found `tuple[Self, Self]`
- corporate/lib/remote_billing_util.py:168:8: error[unresolved-attribute] Type `Self` has no attribute `deactivated`
- corporate/lib/remote_billing_util.py:173:16: error[invalid-return-type] Return type does not match returned value: expected `tuple[RemoteZulipServer, RemoteServerBillingUser | None]`, found `tuple[Self, None]`
- corporate/lib/remote_billing_util.py:182:12: error[invalid-return-type] Return type does not match returned value: expected `tuple[RemoteZulipServer, RemoteServerBillingUser | None]`, found `tuple[Self, Self | None]`
- corporate/lib/stripe.py:391:16: error[invalid-return-type] Return type does not match returned value: expected `CustomerPlanOffer | None`, found `Self | None`
- corporate/lib/stripe.py:1049:16: error[invalid-return-type] Return type does not match returned value: expected `CustomerPlan | None`, found `Self | None`
- corporate/lib/stripe.py:1074:16: error[invalid-return-type] Return type does not match returned value: expected `CustomerPlan | None`, found `Self`
- corporate/lib/stripe.py:1202:17: error[unresolved-attribute] Unresolved attribute `status` on type `Self`.
- corporate/lib/stripe.py:1961:16: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/lib/stripe.py:1974:17: error[unresolved-attribute] Unresolved attribute `invoiced_through` on type `Self`.
- corporate/lib/stripe.py:2031:29: error[unresolved-attribute] Type `Self` has no attribute `fixed_price`
- corporate/lib/stripe.py:2033:27: error[unresolved-attribute] Type `Self` has no attribute `tier`
- corporate/lib/stripe.py:2044:20: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/lib/stripe.py:2054:33: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/lib/stripe.py:2055:33: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/lib/stripe.py:2192:9: error[unresolved-attribute] Unresolved attribute `invoiced_through` on type `Self`.
- corporate/lib/stripe.py:2201:39: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/lib/stripe.py:2210:40: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/lib/stripe.py:2288:24: error[invalid-return-type] Return type does not match returned value: expected `tuple[CustomerPlan | None, LicenseLedger | None]`, found `tuple[None, Self]`
- corporate/lib/stripe.py:2333:24: error[invalid-return-type] Return type does not match returned value: expected `tuple[CustomerPlan | None, LicenseLedger | None]`, found `tuple[None, Self]`
- corporate/lib/stripe.py:2352:17: error[unresolved-attribute] Unresolved attribute `status` on type `Self`.
- corporate/lib/stripe.py:2354:47: error[unresolved-attribute] Type `Self` has no attribute `tier`
- corporate/lib/stripe.py:2355:24: error[invalid-return-type] Return type does not match returned value: expected `tuple[CustomerPlan | None, LicenseLedger | None]`, found `tuple[None, Self]`
- corporate/lib/stripe.py:2403:43: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/lib/stripe.py:2407:24: error[invalid-return-type] Return type does not match returned value: expected `tuple[CustomerPlan | None, LicenseLedger | None]`, found `tuple[Self, Self]`
- corporate/lib/stripe.py:2449:44: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/lib/stripe.py:2453:24: error[invalid-return-type] Return type does not match returned value: expected `tuple[CustomerPlan | None, LicenseLedger | None]`, found `tuple[Self, Self]`
- corporate/lib/stripe.py:2469:20: error[invalid-return-type] Return type does not match returned value: expected `CustomerPlan | None`, found `Self | None`
- corporate/lib/stripe.py:2892:17: warning[possibly-unbound-attribute] Attribute `get_default` on type `Field[Unknown, Unknown] | ForeignObjectRel | GenericForeignKey` is possibly unbound
- corporate/lib/stripe.py:3188:16: error[unresolved-attribute] Type `Self` has no attribute `automanage_licenses`
- corporate/lib/stripe.py:3442:17: error[unresolved-attribute] Type `Self` has no attribute `type`
- corporate/lib/stripe.py:3446:32: error[unresolved-attribute] Type `Self` has no attribute `to_dict`
- corporate/lib/stripe.py:3457:39: error[unresolved-attribute] Type `Self` has no attribute `to_dict`
- corporate/lib/stripe.py:3859:27: error[unresolved-attribute] Type `Self` has no attribute `tier`
- corporate/lib/stripe.py:3872:9: error[unresolved-attribute] Unresolved attribute `invoiced_through` on type `Self`.
- corporate/lib/stripe.py:3914:81: error[unresolved-attribute] Type `Self` has no attribute `tier`
- corporate/lib/stripe.py:3927:9: error[unresolved-attribute] Unresolved attribute `invoiced_through` on type `Self`.
- corporate/lib/stripe.py:4130:20: error[invalid-return-type] Return type does not match returned value: expected `Customer`, found `Self`
- corporate/lib/stripe.py:4135:20: error[invalid-return-type] Return type does not match returned value: expected `Customer`, found `Self`
- corporate/lib/stripe.py:4534:21: error[unresolved-attribute] Type `Self` has no attribute `annual_discounted_price`
- corporate/lib/stripe.py:4535:21: error[unresolved-attribute] Type `Self` has no attribute `monthly_discounted_price`
- corporate/lib/stripe.py:4537:13: error[unresolved-attribute] Unresolved attribute `flat_discounted_months` on type `Self`.
- corporate/lib/stripe.py:4540:16: error[invalid-return-type] Return type does not match returned value: expected `Customer`, found `Self`
- corporate/lib/stripe.py:4969:21: error[unresolved-attribute] Type `Self` has no attribute `annual_discounted_price`
- corporate/lib/stripe.py:4970:21: error[unresolved-attribute] Type `Self` has no attribute `monthly_discounted_price`
- corporate/lib/stripe.py:4972:13: error[unresolved-attribute] Unresolved attribute `flat_discounted_months` on type `Self`.
- corporate/lib/stripe.py:4975:16: error[invalid-return-type] Return type does not match returned value: expected `Customer`, found `Self`
- corporate/lib/support.py:392:17: error[unresolved-attribute] Type `Self` has no attribute `end_time`
- corporate/lib/support.py:435:17: error[unresolved-attribute] Type `Self` has no attribute `end_time`
- corporate/lib/support.py:460:24: error[unresolved-attribute] Type `Self` has no attribute `event_time`
- corporate/models/customers.py:81:12: error[invalid-return-type] Return type does not match returned value: expected `Customer | None`, found `Self | None`
- corporate/models/customers.py:85:12: error[invalid-return-type] Return type does not match returned value: expected `Customer | None`, found `Self | None`
- corporate/models/customers.py:89:12: error[invalid-return-type] Return type does not match returned value: expected `Customer | None`, found `Self | None`
- corporate/models/plans.py:256:12: error[invalid-return-type] Return type does not match returned value: expected `CustomerPlan | None`, found `Self | None`
- corporate/models/stripe_state.py:45:12: error[invalid-return-type] Return type does not match returned value: expected `Event | None`, found `Self | None`
- corporate/tests/test_activity_views.py:177:24: error[unresolved-attribute] Type `Self` has no attribute `last_updated`
- corporate/tests/test_activity_views.py:215:63: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_activity_views.py:219:70: error[unresolved-attribute] Type `Self` has no attribute `uuid`
- corporate/tests/test_activity_views.py:314:28: error[unresolved-attribute] Type `Self` has no attribute `last_updated`
- corporate/tests/test_activity_views.py:333:18: error[invalid-argument-type] Argument to function `add_plan` is incorrect: Expected `Customer`, found `Self`
- corporate/tests/test_activity_views.py:334:28: error[invalid-argument-type] Argument to function `add_audit_log_data` is incorrect: Expected `RemoteZulipServer`, found `Self`
- corporate/tests/test_activity_views.py:339:18: error[invalid-argument-type] Argument to function `add_plan` is incorrect: Expected `Customer`, found `Self`
- corporate/tests/test_activity_views.py:340:28: error[invalid-argument-type] Argument to function `add_audit_log_data` is incorrect: Expected `RemoteZulipServer`, found `Self`
- corporate/tests/test_activity_views.py:341:28: error[invalid-argument-type] Argument to function `add_audit_log_data` is incorrect: Expected `RemoteZulipServer`, found `Self`
- corporate/tests/test_activity_views.py:342:28: error[invalid-argument-type] Argument to function `add_audit_log_data` is incorrect: Expected `RemoteZulipServer`, found `Self`
- corporate/tests/test_activity_views.py:347:18: error[invalid-argument-type] Argument to function `add_plan` is incorrect: Expected `Customer`, found `Self`
- corporate/tests/test_activity_views.py:348:28: error[unresolved-attribute] Type `Self` has no attribute `server`
- corporate/tests/test_activity_views.py:348:42: error[invalid-argument-type] Argument to function `add_audit_log_data` is incorrect: Expected `RemoteRealm | None`, found `Self`
- corporate/tests/test_activity_views.py:353:18: error[invalid-argument-type] Argument to function `add_plan` is incorrect: Expected `Customer`, found `Self`
- corporate/tests/test_activity_views.py:354:28: error[unresolved-attribute] Type `Self` has no attribute `server`
- corporate/tests/test_activity_views.py:354:42: error[invalid-argument-type] Argument to function `add_audit_log_data` is incorrect: Expected `RemoteRealm | None`, found `Self`
- corporate/tests/test_activity_views.py:359:18: error[invalid-argument-type] Argument to function `add_plan` is incorrect: Expected `Customer`, found `Self`
- corporate/tests/test_activity_views.py:360:28: error[unresolved-attribute] Type `Self` has no attribute `server`
- corporate/tests/test_activity_views.py:360:42: error[invalid-argument-type] Argument to function `add_audit_log_data` is incorrect: Expected `RemoteRealm | None`, found `Self`
- corporate/tests/test_activity_views.py:362:25: error[unresolved-attribute] Type `Self` has no attribute `server`
- corporate/tests/test_activity_views.py:376:18: error[invalid-argument-type] Argument to function `add_plan` is incorrect: Expected `Customer`, found `Self`
- corporate/tests/test_activity_views.py:377:28: error[unresolved-attribute] Type `Self` has no attribute `server`
- corporate/tests/test_activity_views.py:377:42: error[invalid-argument-type] Argument to function `add_audit_log_data` is incorrect: Expected `RemoteRealm | None`, found `Self`
- corporate/tests/test_remote_billing.py:126:30: error[unresolved-attribute] Type `Self` has no attribute `user_uuid`
- corporate/tests/test_remote_billing.py:127:30: error[unresolved-attribute] Type `Self` has no attribute `email`
- corporate/tests/test_remote_billing.py:130:30: error[unresolved-attribute] Type `Self` has no attribute `created_user`
- corporate/tests/test_remote_billing.py:131:30: error[unresolved-attribute] Type `Self` has no attribute `date_joined`
- corporate/tests/test_remote_billing.py:169:36: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_remote_billing.py:179:26: error[unresolved-attribute] Type `Self` has no attribute `last_login`
- corporate/tests/test_remote_billing.py:443:26: error[unresolved-attribute] Type `Self` has no attribute `user_uuid`
- corporate/tests/test_remote_billing.py:444:26: error[unresolved-attribute] Type `Self` has no attribute `tos_version`
- corporate/tests/test_remote_billing.py:463:26: error[unresolved-attribute] Type `Self` has no attribute `user_uuid`
- corporate/tests/test_remote_billing.py:464:26: error[unresolved-attribute] Type `Self` has no attribute `tos_version`
- corporate/tests/test_remote_billing.py:688:29: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_remote_billing.py:688:51: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_remote_billing.py:699:26: error[unresolved-attribute] Type `Self` has no attribute `user_uuid`
- corporate/tests/test_remote_billing.py:700:26: error[unresolved-attribute] Type `Self` has no attribute `email`
- corporate/tests/test_remote_billing.py:703:26: error[unresolved-attribute] Type `Self` has no attribute `created_user`
- corporate/tests/test_remote_billing.py:719:26: error[unresolved-attribute] Type `Self` has no attribute `created_user`
- corporate/tests/test_remote_billing.py:725:58: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_remote_billing.py:792:60: error[invalid-argument-type] Argument to function `get_customer_by_remote_realm` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:833:56: error[invalid-argument-type] Argument to function `get_customer_by_remote_realm` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:835:26: error[unresolved-attribute] Type `Self` has no attribute `host`
- corporate/tests/test_remote_billing.py:836:49: error[invalid-argument-type] Argument to function `get_customer_by_remote_realm` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:843:13: error[unresolved-attribute] Type `Self` has no attribute `plan_type`
- corporate/tests/test_remote_billing.py:850:39: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:887:59: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:898:9: error[unresolved-attribute] Unresolved attribute `plan_type` on type `Self`.
- corporate/tests/test_remote_billing.py:908:87: error[unresolved-attribute] Type `Self` has no attribute `server`
- corporate/tests/test_remote_billing.py:908:127: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_remote_billing.py:918:9: error[unresolved-attribute] Unresolved attribute `status` on type `Self`.
- corporate/tests/test_remote_billing.py:923:9: error[unresolved-attribute] Unresolved attribute `status` on type `Self`.
- corporate/tests/test_remote_billing.py:933:87: error[unresolved-attribute] Type `Self` has no attribute `server`
- corporate/tests/test_remote_billing.py:933:127: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_remote_billing.py:945:9: error[unresolved-attribute] Unresolved attribute `status` on type `Self`.
- corporate/tests/test_remote_billing.py:958:87: error[unresolved-attribute] Type `Self` has no attribute `server`
- corporate/tests/test_remote_billing.py:958:127: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_remote_billing.py:982:55: error[invalid-argument-type] Argument to function `get_customer_by_remote_realm` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:990:26: error[unresolved-attribute] Type `Self` has no attribute `plan_type`
- corporate/tests/test_remote_billing.py:1059:60: error[invalid-argument-type] Argument to function `get_customer_by_remote_realm` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:1064:26: error[unresolved-attribute] Type `Self` has no attribute `customer`
- corporate/tests/test_remote_billing.py:1094:56: error[invalid-argument-type] Argument to function `get_customer_by_remote_realm` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:1096:26: error[unresolved-attribute] Type `Self` has no attribute `host`
- corporate/tests/test_remote_billing.py:1097:49: error[invalid-argument-type] Argument to function `get_customer_by_remote_realm` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:1103:26: error[unresolved-attribute] Type `Self` has no attribute `plan_type`
- corporate/tests/test_remote_billing.py:1108:53: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `RemoteRealm`, found `Self`
- corporate/tests/test_remote_billing.py:1317:36: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_remote_billing.py:1324:26: error[unresolved-attribute] Type `Self` has no attribute `last_login`
- corporate/tests/test_remote_billing.py:1446:26: error[unresolved-attribute] Type `Self` has no attribute `email`
- corporate/tests/test_remote_billing.py:1449:26: error[unresolved-attribute] Type `Self` has no attribute `created_user`
- corporate/tests/test_remote_billing.py:1450:26: error[unresolved-attribute] Type `Self` has no attribute `date_joined`
- corporate/tests/test_stripe.py:694:13: error[unresolved-attribute] Type `Self` has no attribute `stripe_invoice_id`
- corporate/tests/test_stripe.py:700:13: error[unresolved-attribute] Type `Self` has no attribute `stripe_invoice_id`
- corporate/tests/test_stripe.py:706:32: error[unresolved-attribute] Type `Self` has no attribute `stripe_invoice_id`
- corporate/tests/test_stripe.py:724:36: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:1032:32: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:1319:32: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:1571:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:1572:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:1577:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:1578:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:1624:13: error[unresolved-attribute] Unresolved attribute `next_invoice_date` on type `Self`.
- corporate/tests/test_stripe.py:1647:13: error[unresolved-attribute] Unresolved attribute `next_invoice_date` on type `Self`.
- corporate/tests/test_stripe.py:1653:9: error[unresolved-attribute] Unresolved attribute `fixed_price` on type `Self`.
- corporate/tests/test_stripe.py:1654:9: error[unresolved-attribute] Unresolved attribute `price_per_license` on type `Self`.
- corporate/tests/test_stripe.py:1681:36: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:1795:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:1796:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:1823:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:1824:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:1827:30: error[unresolved-attribute] Type `Self` has no attribute `billing_cycle_anchor`
- corporate/tests/test_stripe.py:1856:36: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:1970:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:1971:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:2008:17: error[unresolved-attribute] Type `Self` has no attribute `licenses_at_next_renewal`
- corporate/tests/test_stripe.py:2013:17: error[unresolved-attribute] Type `Self` has no attribute `licenses_at_next_renewal`
- corporate/tests/test_stripe.py:2020:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:2021:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:2023:30: error[unresolved-attribute] Type `Self` has no attribute `billing_cycle_anchor`
- corporate/tests/test_stripe.py:2061:36: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:2173:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:2224:54: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:2243:26: error[unresolved-attribute] Type `Self` has no attribute `licenses`
- corporate/tests/test_stripe.py:2244:26: error[unresolved-attribute] Type `Self` has no attribute `licenses_at_next_renewal`
- corporate/tests/test_stripe.py:2276:54: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:2288:26: error[unresolved-attribute] Type `Self` has no attribute `licenses`
- corporate/tests/test_stripe.py:2289:26: error[unresolved-attribute] Type `Self` has no attribute `licenses_at_next_renewal`
- corporate/tests/test_stripe.py:2341:54: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:2353:26: error[unresolved-attribute] Type `Self` has no attribute `licenses`
- corporate/tests/test_stripe.py:2354:26: error[unresolved-attribute] Type `Self` has no attribute `licenses_at_next_renewal`
- corporate/tests/test_stripe.py:2372:16: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:2376:26: error[unresolved-attribute] Type `Self` has no attribute `licenses`
- corporate/tests/test_stripe.py:2377:26: error[unresolved-attribute] Type `Self` has no attribute `licenses_at_next_renewal`
- corporate/tests/test_stripe.py:2381:9: error[unresolved-attribute] Unresolved attribute `minimum_licenses` on type `Self`.
- corporate/tests/test_stripe.py:2387:66: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:2399:9: error[unresolved-attribute] Unresolved attribute `minimum_licenses` on type `Self`.
- corporate/tests/test_stripe.py:2405:70: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:2677:9: error[unresolved-attribute] Unresolved attribute `exempt_from_license_number_check` on type `Self`.
- corporate/tests/test_stripe.py:2872:26: error[unresolved-attribute] Type `Self` has no attribute `org_website`
- corporate/tests/test_stripe.py:2873:26: error[unresolved-attribute] Type `Self` has no attribute `org_description`
- corporate/tests/test_stripe.py:2875:13: error[unresolved-attribute] Type `Self` has no attribute `org_type`
- corporate/tests/test_stripe.py:2978:9: error[unresolved-attribute] Unresolved attribute `sponsorship_pending` on type `Self`.
- corporate/tests/test_stripe.py:3061:34: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:3062:90: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:3062:122: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:3234:30: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:3393:34: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:3443:26: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:3451:26: error[unresolved-attribute] Type `Self` has no attribute `event_type`
- corporate/tests/test_stripe.py:3452:26: error[unresolved-attribute] Type `Self` has no attribute `acting_user`
- corporate/tests/test_stripe.py:3468:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:3480:27: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:3506:30: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:3575:26: error[unresolved-attribute] Type `Self` has no attribute `realm`
- corporate/tests/test_stripe.py:3576:26: error[unresolved-attribute] Type `Self` has no attribute `extra_data`
- corporate/tests/test_stripe.py:3577:26: error[unresolved-attribute] Type `Self` has no attribute `extra_data`
- corporate/tests/test_stripe.py:3697:30: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:3806:30: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:3932:26: error[unresolved-attribute] Type `Self` has no attribute `realm`
- corporate/tests/test_stripe.py:3933:26: error[unresolved-attribute] Type `Self` has no attribute `extra_data`
- corporate/tests/test_stripe.py:3934:26: error[unresolved-attribute] Type `Self` has no attribute `extra_data`
- corporate/tests/test_stripe.py:3989:34: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:3997:26: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4011:26: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4029:34: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:4042:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4043:26: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4045:9: error[unresolved-attribute] Unresolved attribute `next_invoice_date` on type `Self`.
- corporate/tests/test_stripe.py:4050:27: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4051:26: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4062:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4064:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4078:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4079:31: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4101:30: error[unresolved-attribute] Type `Self` has no attribute `invoiced_through`
- corporate/tests/test_stripe.py:4117:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4119:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4132:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4133:31: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4155:30: error[unresolved-attribute] Type `Self` has no attribute `invoiced_through`
- corporate/tests/test_stripe.py:4173:30: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4175:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4184:30: error[unresolved-attribute] Type `Self` has no attribute `licenses`
- corporate/tests/test_stripe.py:4185:30: error[unresolved-attribute] Type `Self` has no attribute `licenses_at_next_renewal`
- corporate/tests/test_stripe.py:4197:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4198:30: error[unresolved-attribute] Type `Self` has no attribute `invoiced_through`
- corporate/tests/test_stripe.py:4199:31: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4242:38: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:4293:31: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4294:30: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4354:38: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:4376:38: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:4404:34: error[unresolved-attribute] Type `Self` has no attribute `id`
- corporate/tests/test_stripe.py:4506:32: error[unresolved-attribute] Type `Self` has no attribute `stripe_customer_id`
- corporate/tests/test_stripe.py:4614:9: error[unresolved-attribute] Unresolved attribute `exempt_from_license_number_check` on type `Self`.
- corporate/tests/test_stripe.py:4630:13: error[unresolved-attribute] Type `Self` has no attribute `licenses_at_next_renewal`
- corporate/tests/test_stripe.py:4646:9: error[unresolved-attribute] Unresolved attribute `exempt_from_license_number_check` on type `Self`.
- corporate/tests/test_stripe.py:4658:26: error[unresolved-attribute] Type `Self` has no attribute `licenses_at_next_renewal`
- corporate/tests/test_stripe.py:4659:26: error[unresolved-attribute] Type `Self` has no attribute `licenses`
- corporate/tests/test_stripe.py:4772:26: error[unresolved-attribute] Type `Self` has no attribute `next_invoice_date`
- corporate/tests/test_stripe.py:4774:26: error[unresolved-attribute] Type `Self` has no attribute `status`
- corporate/tests/test_stripe.py:4783:26: error[unresolved-attribute] Type `Self` has no attribute `licenses`
- corporate/tes...*[Comment body truncated]*

@dcreager
Copy link
Member Author

dcreager commented Aug 7, 2025

Doh! The size of Type has gone up from 16 bytes to 24 😞

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Aug 7, 2025
@dcreager dcreager marked this pull request as draft August 7, 2025 12:05
* origin/main:
  [ty] Implemented support for "rename" language server feature (#19551)
  [ty] Reduce size of member table (#19572)
  [ty] Move server capabilities creation (#19798)
  [ty] Repurpose `FunctionType.into_bound_method_type` to return `BoundMethodType` (#19793)
  [ty] Validate writes to `TypedDict` keys (#19782)
  [ty] Add support for using the test command emitted when a mdtest fails (#19794)
@dcreager
Copy link
Member Author

dcreager commented Aug 7, 2025

Doh! The size of Type has gone up from 16 bytes to 24 😞

I made BoundTypeVarInstance an interned struct to bring the size of Type back down. That eliminates one of the proposed benefits of this PR (fewer interned structs), but I think there's still value in the additional type safety.

Copy link
Contributor

github-actions bot commented Aug 7, 2025

Diagnostic diff on typing conformance tests

Changes were detected when running ty on typing conformance tests
--- old-output.txt	2025-08-11 17:44:43.096472962 +0000
+++ new-output.txt	2025-08-11 17:44:43.163473111 +0000
@@ -84,9 +84,9 @@
 aliases_typealiastype.py:63:42: error[invalid-type-form] Boolean operations are not allowed in type expressions
 aliases_typealiastype.py:64:42: error[invalid-type-form] F-strings are not allowed in type expressions
 aliases_typealiastype.py:66:47: error[unresolved-reference] Name `BadAlias21` used when not defined
-aliases_variance.py:18:24: error[non-subscriptable] Cannot subscript object of type `<class 'ClassA[T_co]'>` with no `__class_getitem__` method
-aliases_variance.py:28:16: error[non-subscriptable] Cannot subscript object of type `<class 'ClassA[T_co]'>` with no `__class_getitem__` method
-aliases_variance.py:44:16: error[non-subscriptable] Cannot subscript object of type `<class 'ClassB[T_co, T_contra]'>` with no `__class_getitem__` method
+aliases_variance.py:18:24: error[non-subscriptable] Cannot subscript object of type `<class 'ClassA[typing.TypeVar("T_co")]'>` with no `__class_getitem__` method
+aliases_variance.py:28:16: error[non-subscriptable] Cannot subscript object of type `<class 'ClassA[typing.TypeVar("T_co")]'>` with no `__class_getitem__` method
+aliases_variance.py:44:16: error[non-subscriptable] Cannot subscript object of type `<class 'ClassB[typing.TypeVar("T_co"), typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
 annotations_forward_refs.py:22:7: error[unresolved-reference] Name `ClassA` used when not defined
 annotations_forward_refs.py:23:12: error[unresolved-reference] Name `ClassA` used when not defined
 annotations_forward_refs.py:49:10: error[invalid-type-form] Variable of type `Literal[1]` is not allowed in a type expression
@@ -400,7 +400,7 @@
 generics_defaults_referential.py:95:1: error[type-assertion-failure] Argument does not have asserted type `@Todo`
 generics_defaults_specialization.py:26:5: error[type-assertion-failure] Argument does not have asserted type `SomethingWithNoDefaults[int, str]`
 generics_defaults_specialization.py:27:5: error[type-assertion-failure] Argument does not have asserted type `SomethingWithNoDefaults[int, bool]`
-generics_defaults_specialization.py:30:1: error[non-subscriptable] Cannot subscript object of type `<class 'SomethingWithNoDefaults[int, DefaultStrT]'>` with no `__class_getitem__` method
+generics_defaults_specialization.py:30:1: error[non-subscriptable] Cannot subscript object of type `<class 'SomethingWithNoDefaults[int, typing.TypeVar("DefaultStrT", default=str)]'>` with no `__class_getitem__` method
 generics_defaults_specialization.py:45:1: error[type-assertion-failure] Argument does not have asserted type `@Todo`
 generics_paramspec_basic.py:27:38: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `int`
 generics_paramspec_components.py:83:18: error[parameter-already-assigned] Multiple values provided for parameter 1 (`x`) of function `foo`
@@ -436,16 +436,16 @@
 generics_self_advanced.py:18:1: error[type-assertion-failure] Argument does not have asserted type `ParentA`
 generics_self_advanced.py:19:1: error[type-assertion-failure] Argument does not have asserted type `ChildA`
 generics_self_advanced.py:28:25: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `Self@method1`
-generics_self_advanced.py:35:9: error[type-assertion-failure] Argument does not have asserted type `Self`
-generics_self_advanced.py:36:9: error[type-assertion-failure] Argument does not have asserted type `list[Self]`
-generics_self_advanced.py:37:9: error[type-assertion-failure] Argument does not have asserted type `Self`
-generics_self_advanced.py:38:9: error[type-assertion-failure] Argument does not have asserted type `Self`
-generics_self_advanced.py:43:9: error[type-assertion-failure] Argument does not have asserted type `list[Self]`
-generics_self_advanced.py:44:9: error[type-assertion-failure] Argument does not have asserted type `Self`
-generics_self_advanced.py:45:9: error[type-assertion-failure] Argument does not have asserted type `Self`
-generics_self_attributes.py:26:33: error[invalid-argument-type] Argument is incorrect: Expected `Self | None`, found `LinkedList[int]`
-generics_self_attributes.py:29:5: error[invalid-assignment] Object of type `OrdinalLinkedList` is not assignable to attribute `next` of type `Self | None`
-generics_self_attributes.py:32:5: error[invalid-assignment] Object of type `LinkedList[int]` is not assignable to attribute `next` of type `Self | None`
+generics_self_advanced.py:35:9: error[type-assertion-failure] Argument does not have asserted type `typing.Self`
+generics_self_advanced.py:36:9: error[type-assertion-failure] Argument does not have asserted type `list[typing.Self]`
+generics_self_advanced.py:37:9: error[type-assertion-failure] Argument does not have asserted type `typing.Self`
+generics_self_advanced.py:38:9: error[type-assertion-failure] Argument does not have asserted type `typing.Self`
+generics_self_advanced.py:43:9: error[type-assertion-failure] Argument does not have asserted type `list[typing.Self]`
+generics_self_advanced.py:44:9: error[type-assertion-failure] Argument does not have asserted type `typing.Self`
+generics_self_advanced.py:45:9: error[type-assertion-failure] Argument does not have asserted type `typing.Self`
+generics_self_attributes.py:26:33: error[invalid-argument-type] Argument is incorrect: Expected `typing.Self | None`, found `LinkedList[int]`
+generics_self_attributes.py:29:5: error[invalid-assignment] Object of type `OrdinalLinkedList` is not assignable to attribute `next` of type `typing.Self | None`
+generics_self_attributes.py:32:5: error[invalid-assignment] Object of type `LinkedList[int]` is not assignable to attribute `next` of type `typing.Self | None`
 generics_self_basic.py:14:9: error[type-assertion-failure] Argument does not have asserted type `Self@set_scale`
 generics_self_basic.py:20:16: error[invalid-return-type] Return type does not match returned value: expected `Self@method2`, found `Shape`
 generics_self_basic.py:33:16: error[invalid-return-type] Return type does not match returned value: expected `Self@cls_method2`, found `Shape`
@@ -473,7 +473,7 @@
 generics_self_usage.py:121:37: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `Self@__new__`
 generics_self_usage.py:125:37: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `list[Self@__mul__]`
 generics_syntax_compatibility.py:23:38: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `V@ClassC | K@method1`
-generics_syntax_compatibility.py:26:41: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `M@method2 | K`
+generics_syntax_compatibility.py:26:41: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `M@method2 | K@method2`
 generics_syntax_declarations.py:17:1: error[invalid-generic-class] Cannot both inherit from `typing.Generic` and use PEP 695 type variables
 generics_syntax_declarations.py:25:20: error[invalid-generic-class] Cannot both inherit from subscripted `Protocol` and use PEP 695 type variables
 generics_syntax_declarations.py:32:9: error[unresolved-attribute] Type `T@ClassD` has no attribute `is_integer`
@@ -580,20 +580,20 @@
 generics_variance.py:14:6: error[invalid-legacy-type-variable] A legacy `typing.TypeVar` cannot be both covariant and contravariant
 generics_variance.py:26:27: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `Iterator[T_co@ImmutableList]`
 generics_variance.py:57:28: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `B_co@func`
-generics_variance.py:175:25: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[T_contra]'>` with no `__class_getitem__` method
-generics_variance.py:175:35: error[non-subscriptable] Cannot subscript object of type `<class 'Co[T_co]'>` with no `__class_getitem__` method
-generics_variance.py:179:29: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[T_contra]'>` with no `__class_getitem__` method
-generics_variance.py:179:39: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[T_contra]'>` with no `__class_getitem__` method
-generics_variance.py:183:21: error[non-subscriptable] Cannot subscript object of type `<class 'Co[T_co]'>` with no `__class_getitem__` method
-generics_variance.py:183:27: error[non-subscriptable] Cannot subscript object of type `<class 'Co[T_co]'>` with no `__class_getitem__` method
-generics_variance.py:187:25: error[non-subscriptable] Cannot subscript object of type `<class 'Co[T_co]'>` with no `__class_getitem__` method
-generics_variance.py:187:31: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[T_contra]'>` with no `__class_getitem__` method
-generics_variance.py:191:33: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[T_contra]'>` with no `__class_getitem__` method
-generics_variance.py:191:43: error[non-subscriptable] Cannot subscript object of type `<class 'Co[T_co]'>` with no `__class_getitem__` method
-generics_variance.py:191:49: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[T_contra]'>` with no `__class_getitem__` method
-generics_variance.py:196:5: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[T_contra]'>` with no `__class_getitem__` method
-generics_variance.py:196:15: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[T_contra]'>` with no `__class_getitem__` method
-generics_variance.py:196:25: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[T_contra]'>` with no `__class_getitem__` method
+generics_variance.py:175:25: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
+generics_variance.py:175:35: error[non-subscriptable] Cannot subscript object of type `<class 'Co[typing.TypeVar("T_co")]'>` with no `__class_getitem__` method
+generics_variance.py:179:29: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
+generics_variance.py:179:39: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
+generics_variance.py:183:21: error[non-subscriptable] Cannot subscript object of type `<class 'Co[typing.TypeVar("T_co")]'>` with no `__class_getitem__` method
+generics_variance.py:183:27: error[non-subscriptable] Cannot subscript object of type `<class 'Co[typing.TypeVar("T_co")]'>` with no `__class_getitem__` method
+generics_variance.py:187:25: error[non-subscriptable] Cannot subscript object of type `<class 'Co[typing.TypeVar("T_co")]'>` with no `__class_getitem__` method
+generics_variance.py:187:31: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
+generics_variance.py:191:33: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
+generics_variance.py:191:43: error[non-subscriptable] Cannot subscript object of type `<class 'Co[typing.TypeVar("T_co")]'>` with no `__class_getitem__` method
+generics_variance.py:191:49: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
+generics_variance.py:196:5: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
+generics_variance.py:196:15: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
+generics_variance.py:196:25: error[non-subscriptable] Cannot subscript object of type `<class 'Contra[typing.TypeVar("T_contra")]'>` with no `__class_getitem__` method
 generics_variance_inference.py:19:26: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `T3@ClassA`
 generics_variance_inference.py:24:5: error[invalid-assignment] Object of type `ClassA[int | float, int, int]` is not assignable to `ClassA[int, int, int]`
 generics_variance_inference.py:25:5: error[invalid-assignment] Object of type `ClassA[int | float, int, int]` is not assignable to `ClassA[int | float, int | float, int]`

Copy link
Contributor

github-actions bot commented Aug 7, 2025

ecosystem-analyzer results

Lint rule Added Removed Changed
unresolved-attribute 0 2,856 0
invalid-argument-type 37 746 21
invalid-return-type 0 166 1
possibly-unbound-attribute 5 43 0
non-subscriptable 0 0 20
invalid-assignment 0 14 0
no-matching-overload 3 0 0
unused-ignore-comment 2 0 0
call-non-callable 1 0 0
not-iterable 0 1 0
unsupported-operator 0 1 0
Total 48 3,827 42

Full report with detailed diff

@dcreager
Copy link
Member Author

dcreager commented Aug 7, 2025

The strawberry ecosystem failure is interesting:

[error] invalid-argument-type - :167:17 - Argument to function `wrap` is incorrect: Expected `_T@scalar`, found `_T@scalar`

with some extra debug statements, the two typevars actually have different binding contexts:

 -> lhs Definition(Definition { [salsa id]: Id(1461), file: File(System("/home/dcreager/git/code-nav/strawberry/strawberry/types/scalar.py")), file_scope: FileScopeId(0), place: Symbol(ScopedSymbolId(25)), kind: Function(AstNodeRef { kind: StmtFunctionDef, range: 4370..6323 }), is_reexported: true })
 -> rhs Definition(Definition { [salsa id]: Id(1455), file: File(System("/home/dcreager/git/code-nav/strawberry/strawberry/types/scalar.py")), file_scope: FileScopeId(0), place: Symbol(ScopedSymbolId(25)), kind: Function(AstNodeRef { kind: StmtFunctionDef, range: 3784..4118 }), is_reexported: true })

because the scalar function is overloaded. The lhs has a binding context of the implementation, while the rhs has a binding context of one of the overloads.

Going to dig into this some more

@dcreager
Copy link
Member Author

dcreager commented Aug 7, 2025

The lhs has a binding context of the implementation, while the rhs has a binding context of one of the overloads.

The reason for this was interesting! Whenever we use a typevar in a type context, we need to determine if the typevar is bound at that point in the source. We walk through the enclosing scopes, to see if any of them are a generic class/function that binds the typevar in question. That requires knowing the generic context of said classes/functions. For a generic function, we find the infered type for the definition (which should be a Type::FunctionType), grab its signature (which is a CallableSignature, since the function might be overloaded), and then take the generic context of the final per-overload Signature.

This works because we create a FunctionType/FunctionLiteral wrapper around every overload; each one only "sees" the earlier overloads when you ask e.g. for "all overloads and implementation". So the last overload in the CallableSignature should be the one defined by the enclosing scope that we're currently looking at.

EXCEPT! We don't include the implementation when producing the signature of a function! This is almost always what you want. But not here! For a typevar reference inside the implementation body of an overloaded function, we would grab the signature of last non-implementation overload, and use that as the binding context.

The fix is to add an additional method on FunctionType that returns the Signature of the very specific overload that the type is pointing at, and to use that when walking the enclosing scopes.

@dcreager
Copy link
Member Author

dcreager commented Aug 7, 2025

The remaining new ecosystem diagnostics look to all be from either:

  • a typing.Self in an attribute annotation
  • not introducing a new generic context for Callable types

@dcreager dcreager marked this pull request as ready for review August 7, 2025 17:24
* main:
  Update Rust toolchain to 1.89 (#19807)
  [ty] Add `ty.inlayHints.variableTypes` server option (#19780)
  [ty] Add failing tests for tuple subclasses (#19803)
  [ty] Add `ty.experimental.rename` server setting (#19800)
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

Comment on lines 374 to 377
typing.TypeVar[T: int = bool]
---------------------------------------------
```python
T@Alias
typing.TypeVar[T: int = bool]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this display change indicate that we now consider T unbound here? Is that right? The type parameter to list is a type expression, so I would expect this use of T to be inferred as Type::TypeVar, and T should be bound to the type alias context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It always was unbound, we just couldn't see it before! You're right that it should be bound, but we're not creating GenericContexts for type aliases yet [playground]:

type Alias[T] = list[T]
reveal_type(Alias[int])  # revealed: @Todo

Once type aliases have a generic context, we can update enclosing_generic_scopes to return those, and then this will become bound as it should. I'll add a TODO comment here.

@@ -102,7 +102,7 @@ def silence[T: type[BaseException]](
try:
func()
except exception_type as e:
reveal_type(e) # revealed: T'instance
reveal_type(e) # revealed: T'instance@silence
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly it pre-exists this PR, but where does the 'instance in this typevar's name come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T is bound to an exception type, but the actual caught expression will be an instance of that type. So it's not correct to reveal T@silence here, since that would be the type of type(e). Type::to_instance will synthesize a new typevar with this modified name. Though a better representation might be letting NominalInstance wrap a typevar?

Copy link
Contributor

@carljm carljm Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having NominalInstance wrap a typevar seems like an awkward representation, since it would only be valid for a typevar with upper bound of type[...]. I feel like what we're doing here makes sense, just hard to come up with a good name for it. Not something to worry about in this PR.

As a side note, this code example seems quite difficult for type checkers:

from typing import Callable

def silence[T: type[BaseException]](
    func: Callable[[], None],
    exception_type: T,
) -> T | None:
    try:
        func()
    except exception_type as e:
        reveal_type(e)
        return e  # should be a type error, only returning `type(e)` would be valid

Pyright reveals BaseException*, which is kind of reasonable but what does the * mean? (I think it means "best guess type", which is treated as dynamic.) And then it allows return e, which is clearly a false negative.

Mypy doesn't even allow the except exception_type as e, and then reveals Any.

Pyrefly just panics.

The next interesting bit is to try replacing return e with return type(e), which in principle should be valid. We don't allow that, because we don't track enough metadata to round-trip the T'instance typevar back to T in to_meta_type. (I guess your suggestion of wrapping T rather than synthesizing a new typevar might allow us to fix that.)

Anyway, this is all just musing because it's interesting, not relevant to this PR!

dcreager and others added 9 commits August 11, 2025 09:51
* main: (31 commits)
  Add AIR301 rule (#17707)
  Avoid underflow in default ranges before a BOM (#19839)
  Update actions/download-artifact digest to de96f46 (#19852)
  Update docker/login-action action to v3.5.0 (#19860)
  Update rui314/setup-mold digest to 7344740 (#19853)
  Update cargo-bins/cargo-binstall action to v1.14.4 (#19855)
  Update actions/cache action to v4.2.4 (#19854)
  Update Rust crate hashbrown to v0.15.5 (#19858)
  Update Rust crate camino to v1.1.11 (#19857)
  Update Rust crate proc-macro2 to v1.0.96 (#19859)
  Update dependency ruff to v0.12.8 (#19856)
  SIM905: Fix handling of U+001C..U+001F whitespace (#19849)
  RUF064: offer a safe fix for multi-digit zeros (#19847)
  Clean up unused rendering code in `ruff_linter` (#19832)
  [ty] Add Salsa caching to `TupleType::to_class_type` (#19840)
  [ty] Handle cycles when finding implicit attributes (#19833)
  [ty] fix goto-definition on imports (#19834)
  [ty] Implement stdlib stub mapping (#19529)
  [`flake8-comprehensions`] Fix false positive for `C420` with attribute, subscript, or slice assignment targets (#19513)
  [ty] Implement module-level `__getattr__` support (#19791)
  ...
…eager/bound-typevar

* origin/dcreager/bound-typevar:
  Apply suggestions from code review
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@dcreager dcreager merged commit dc84645 into main Aug 11, 2025
38 checks passed
@dcreager dcreager deleted the dcreager/bound-typevar branch August 11, 2025 19:30
dcreager added a commit that referenced this pull request Aug 11, 2025
* origin/main:
  [ty] Use separate Rust types for bound and unbound type variables (#19796)
dcreager added a commit that referenced this pull request Aug 11, 2025
* dcreager/bound-typevar: (41 commits)
  [ty] Use separate Rust types for bound and unbound type variables (#19796)
  fix ide tests
  better unbound typevar rendering
  Apply suggestions from code review
  [ty] Add `static-frame` as a walltime benchmark (#19844)
  add explanatory comment
  [ty] Update goto range for attribute access to only target the attribute (#19848)
  remove unneeded ord
  add TODO for broken hover test
  better PEP 695 binding context
  Add AIR301 rule (#17707)
  Avoid underflow in default ranges before a BOM (#19839)
  Update actions/download-artifact digest to de96f46 (#19852)
  Update docker/login-action action to v3.5.0 (#19860)
  Update rui314/setup-mold digest to 7344740 (#19853)
  Update cargo-bins/cargo-binstall action to v1.14.4 (#19855)
  Update actions/cache action to v4.2.4 (#19854)
  Update Rust crate hashbrown to v0.15.5 (#19858)
  Update Rust crate camino to v1.1.11 (#19857)
  Update Rust crate proc-macro2 to v1.0.96 (#19859)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ecosystem-analyzer ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider separate Rust types and Type enum variants for bound vs unbound type variables
3 participants