Skip to content

generic mutable class attributes introduce a vent in the type system #11538

Description

@KotlinIsland
from typing import Generic, TypeVar

T = TypeVar("T")


class A(Generic[T]):
    shared_attr: list[T] = []

a1 = A[str]()
a1.shared_attr.append("AMONGUS")

a2 = A[int]()
a2.shared_attr.append(1)

value = a2.class_attr[0]
reveal_type(value)  # revealed type: int, actual value: AMONGUS

In this example the shared attribute shared_attr is imposted upon by different instantiations of that class, causing a sus amongus to be appeared.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions