+1 from me too.
I just had the case yesterday of having to chain a bunch of lists and I
naturally wrote it as [*lst for lst in lst_of_lsts] only to see my IDE complain
:) I've known about itertools.chain() for a while, too. Yet, every time I have
to chain iterables like this, for some reason,
My solution, if anyone comes by here looking for one:
from dataclasses import _create_fn
def patched_create_fn(name: str, args: list[str], body: list[str], **kwargs):
if name == '__init__':
args.append('**kwargs')
if body == ['pass']:
body = []
Thanks for the reply Eric (and for dataclasses). Right now, my solution is
pretty much that, except I do it by monkey-patching dataclasses._init_fn which,
I know, isn't the greatest solution I could find. Your double decorator
solution is cleaner. I'll try that instead. I still end up copying
Oops, there's an indent error for the `extra_info: dict = field(init=False)`
and that last example should be:
def __post_init__(self, **kwargs)
self.name_translations = {
k: kwargs.pop(k)
for k in kwargs.keys()
if k.startswith('name_') # e.g:
Sorry for the double post, if the first one passed... I typed Enter too soon by
accident :(
TL;DR: Add a `strict` keyword option to the dataclass constructor which, by
default (True), would keep the current behavior, but otherwise (False) would
generate an __init__ that accepts arbitrary