https://pantsbuild.org/ logo
#development
Title
# development
c

curved-television-6568

07/21/2021, 5:50 AM
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

hundreds-father-404

07/21/2021, 6:34 AM
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

curved-television-6568

07/21/2021, 11:12 AM
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)