Skip to content

Unsoundness from unbound type variables in attributes #6520

Closed
@msullivan

Description

@msullivan

Minimized from some real code at dropbox exhibiting this failure in a nasty way.

The following code typechecks:

from typing import TypeVar, Generic

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

x: int = A('lol').get()

Here, T is not bound in the class but ends up in the attribute, where it is then matched with the unbound return type variable in get.
(Interestingly, it also works if get returns a different unbound type variable)

A reveal type reports: Revealed type is 'T`-1'

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions