-
-
Notifications
You must be signed in to change notification settings - Fork 424
Add type back to attrs.field() for use in attrs.make_class() #1082
Copy link
Copy link
Closed
Labels
Description
I'm using attrs.make_class() to dynamically construct a class based on other attrs classes, and it would be nice to be able to specify the type of the fields on the generated class using attrs.field() instead of attr.ib(). In other words, this works:
fields = {
field.name: attr.ib(type=field.type)
for field in itertools.chain.from_iterable(
attrs.fields(t) for t in SOME_ATTRS_CLASSES
)
if not field.name.startswith("_")
}
MyClass = attrs.make_class("MyClass", fields)but this does not:
fields = {
field.name: attrs.field(type=field.type)
for field in itertools.chain.from_iterable(
attrs.fields(t) for t in SOME_ATTRS_CLASSES
)
if not field.name.startswith("_")
}
MyClass = attrs.make_class("MyClass", fields)Reactions are currently unavailable