Oh yeah, there's a couple directions we could take...
# development
b
Oh yeah, there's a couple directions we could take this, but here's your teaser:
Copy code
@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
😈
🙌 2
SJ, something something boilerplate?
w
Excelsior!
b
It's not ideal. Ideally the input type is
Iterable
and the value type is
tuple
or
Sequence
But
mypy
doesn't yet support
dataclass_transform
which is where this would work out of the box, no hackery
w
I haven't read the code yet, I just saw boilerplate and went with my gut
b
There's no code yet still need to polish and refactor
h
that'd be great! custom __init__() is so annoying
b
There's other usage of init we can't handle, but this is a great stopgap until dataclass_transform
Actually I might not even go this far. We might just remove
frozen_after_init
in favor of
object.__setattr__
. .. I'll float a PR by
Yeah, so
dataclasses.Field.type
being either a string or the type provided (depending on user declaration and the
annotations
import) is really harshing my mellow
Alternatively we can just use a
mypy
plugin...
Ah ok I think I got it without much shenanigans
OK edited the post, I like this as the least hacks
Annnd I'm burnt out on this 😞