bitter-ability-32190
12/10/2022, 7:50 PM@convert_fields
@dataclass(frozen=True)
class Foo:
x: Iterable[int] = convert_field(tuple)
x = Foo(x=[1, 2]) # mypy is happy
reveal_type(x.x) # reveals Iterable[int]
print(type(x.x)) # prints <class 'tuple'>
I'm coming after you frozen_after_init
😈wide-midnight-78598
12/10/2022, 8:25 PMbitter-ability-32190
12/10/2022, 8:31 PMIterable
and the value type is tuple
or Sequence
mypy
doesn't yet support dataclass_transform
which is where this would work out of the box, no hackerywide-midnight-78598
12/10/2022, 8:40 PMbitter-ability-32190
12/10/2022, 8:41 PMhundreds-father-404
12/10/2022, 8:57 PMbitter-ability-32190
12/10/2022, 11:22 PMfrozen_after_init
in favor of object.__setattr__
. ..
I'll float a PR bydataclasses.Field.type
being either a string or the type provided (depending on user declaration and the annotations
import) is really harshing my mellowmypy
plugin...