I have a question regarding dataclasses and `froze...
# development
c
I have a question regarding dataclasses and
frozen_after_init
. In https://www.pantsbuild.org/docs/style-guide#prefer-dataclasses there’s described how to mutate input parameters during init, but no mention of
InitVar
? https://docs.python.org/3/library/dataclasses.html?highlight=initvar#init-only-variables Uhm.. reading up on it again, is it to circumvent the limitation described in there regarding frozen instances.. ?
There is a tiny performance penalty when using `frozen=True`: 
__init__()
 cannot use simple assignment to initialize fields, and must use 
object.__setattr__()
.
h
I'm afk, but if there's a better way to do things than frozen_after_init, we'd love that! Standardized code is much better than custom utils
👌 1
c
Yeah, that’s it. They have poor support for validating input up-front.. so for frozen instances, that becomes a no-go. In another project I wrote a metaclass to use with dataclasses, that coerced input data to the correct types automatically (when possible, err otherwise), I guess that could work here too. But then again, that wouldn’t be standardized code either.. 😛 (however, it would make for fewer custom inits)