Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeVar constraint type cannot be generic #8012

Closed
nrbnlulu opened this issue May 28, 2024 · 1 comment
Closed

TypeVar constraint type cannot be generic #8012

nrbnlulu opened this issue May 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@nrbnlulu
Copy link

nrbnlulu commented May 28, 2024

Describe the bug
pyright: "TypeVar constraint type cannot be generic"

Code or Screenshots

from collections.abc import Hashable
from typing import Protocol


class HasIDField[K: Hashable](Protocol):
	id: K

	def __hash__(self) -> int: ...


class Repository[K: Hashable, T: HasIDField[K]](Protocol):
	data: list[T]

	def get(self, key: K) -> T | None:
		return next((v for v in self.data if v.id == key), None)

image

VS Code extension or command-line
pyright 1.1.360

Is this a bug or a wanted behaviour? (seems quite reasonable to me...)

@nrbnlulu nrbnlulu added the bug Something isn't working label May 28, 2024
@randolf-scholz
Copy link

randolf-scholz commented May 28, 2024

This is a limitation of the current type system, see python/typing#548 and https://github.com/nekitdev/peps/blob/main/peps/pep-9999.rst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants