Skip to content

TypeVar Should Accept Arguments When Bound To Generic #8278

@rmorshea

Description

@rmorshea

I've posted about this on gitter but haven't gotten a response. Could someone help me understand how I would construct the type spec for a function def (G[T]) -> G[List[G]] where G is any subclass of MyGeneric class. My current approach results in the commented error:

from typing import TypeVar, Generic

Val = TypeVar("Val")

class MyGeneric(Generic[Val]):
    def __call__(self, a: Val) -> Val: ...

T = TypeVar("T")
G = TypeVar("G", bound=MyGeneric)

def listify_my_generic(g: G[T]) -> G[List[T]]: ...  # error: Type variable "G" used with arguments

Here's a playground link:

https://mypy-play.net/?mypy=0.750&python=3.8&gist=290ef32f0638a648674b98873a263d6f

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions