Skip to content

type of class member can be a free type variable #1903

Closed
@rwbarton

Description

@rwbarton

This doesn't make sense:

from typing import TypeVar

T = TypeVar('T')

class A:
    def __init__(self, x: T) -> None:
        self.x = x

a = A(1)
reveal_type(a.x)  # E: Revealed type is 'T`-1'

I guess we need to check that the types of class attributes don't contain free type variables. (Type variables that are bound by the class declaration, i.e. deriving from Generic[T], are okay of course.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions