Skip to content

slotted generic classes are missing __orig_class__ #1436

Closed as not planned
Closed as not planned
@chansoo-google

Description

@chansoo-google

Minimal repro:

import attrs
@attrs.define
class Bar[K, V]:
  key: K
  value: V

y = Bar[str, int]("hello", 123)
get_args(y.__orig_class__) # AttributeError: 'Bar' object has no attribute '__orig_class__'

This is not due to using PEP-695, as verified below:

import attrs
from typing import TypeVar, Generic

K = TypeVar("K")
V = TypeVar("V")
@attrs.define
class Bar(Generic[K, V]):
  key: K
  value: V

y = Bar[str, int]("hello", 123)
get_args(y.__orig_class__) # AttributeError: 'Bar' object has no attribute '__orig_class__'

Variations that work:

import attrs
@attrs.define(slots=False)
class Bar[K, V]:
  key: K
  value: V

y = Bar[str, int]("hello", 123)
get_args(y.__orig_class__) # (str, int)
import dataclasses
@dataclasses.dataclass
class Bar[K, V]:
  key: K
  value: V

y = Bar[str, int]("hello", 123)
get_args(y.__orig_class__) # (str, int)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions