File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -450,6 +450,9 @@ def _transform_attrs(
450
450
if field_transformer is not None :
451
451
attrs = field_transformer (cls , attrs )
452
452
453
+ if inspect .isgenerator (attrs ):
454
+ attrs = tuple (attrs )
455
+
453
456
# Check attr order after executing the field_transformer.
454
457
# Mandatory vs non-mandatory attr order only matters when they are part of
455
458
# 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:
217
217
assert "CAttributes" == fields_type .__name__
218
218
assert issubclass (fields_type , tuple )
219
219
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
+
220
230
221
231
class TestAsDictHook :
222
232
def test_asdict (self ):
You can’t perform that action at this time.
0 commit comments