File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -450,6 +450,9 @@ def _transform_attrs(
450450 if field_transformer is not None :
451451 attrs = field_transformer (cls , attrs )
452452
453+ if inspect .isgenerator (attrs ):
454+ attrs = tuple (attrs )
455+
453456 # Check attr order after executing the field_transformer.
454457 # Mandatory vs non-mandatory attr order only matters when they are part of
455458 # the __init__ signature and when they aren't kw_only (which are moved to
Original file line number Diff line number Diff line change @@ -217,6 +217,16 @@ class C:
217217 assert "CAttributes" == fields_type .__name__
218218 assert issubclass (fields_type , tuple )
219219
220+ def test_hook_generator (self ):
221+ def hook (cls , attribs ):
222+ yield from attribs
223+
224+ @attr .s (auto_attribs = True , field_transformer = hook )
225+ class Base :
226+ x : int
227+
228+ assert ["x" ] == [a .name for a in attr .fields (Base )]
229+
220230
221231class TestAsDictHook :
222232 def test_asdict (self ):
You can’t perform that action at this time.
0 commit comments