Skip to content

unspecialized generic ClassLiteral should be assignable to default-specialized GenericAlias #1832

@carljm

Description

@carljm

With a final generic class P, we don't currently allow the class P itself to be assignable to the type type[P]:

from typing import final 

@final
class P[T]:
    x: T

def expects_type_p(x: type[P]):
    pass

expects_type_p(P)  # this call currently fails but should succeed

Without the @final, this works, because we do implement this assignability to subclass-of types. But for a final class we simplify the subclass-of type to a simple GenericAlias type, and we don't implement assignability of an unspecialized ClassLiteral to a default-specialized GenericAlias type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggenericsBugs or features relating to ty's generics implementationtype propertiessubtyping, assignability, equivalence, and more

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions