ruff
b59f24f7 - [ty] Preserve structural type[Protocol] through generic substitution

Commit
12 days ago
[ty] Preserve structural type[Protocol] through generic substitution ## Generic identity loses `type[P]` **Report entries:** - [psycopg `psycopg/psycopg/_adapters_map.py:143`](https://github.com/psycopg/psycopg/blob/6a52e77dc38827214b294759823a072841b4819f/psycopg/psycopg/_adapters_map.py#L143) - [psycopg `psycopg/psycopg/_adapters_map.py:182`](https://github.com/psycopg/psycopg/blob/6a52e77dc38827214b294759823a072841b4819f/psycopg/psycopg/_adapters_map.py#L182) This is an implementation regression rather than a newly enforced protocol rule: passing `type[P]` through an identity-shaped generic function returns a value displayed as the same `type[P]`, but the PR then rejects assigning it back to `type[P]`. ```python # Merge base: no diagnostic # PR: error[invalid-assignment] Object of type `type[P]` is not assignable to `type[P]` from typing import Protocol, TypeVar class P(Protocol): value: int T = TypeVar("T") def identity(cls: type[T]) -> type[T]: return cls def f(cls: type[P]) -> None: cls = identity(cls) ```
Author
Parents
Loading