-
-
Notifications
You must be signed in to change notification settings - Fork 402
Open
Description
Hi, I'm not sure if this is a bug or a "feature" that is documented somewhere. At least, I haven't encountered it before, so I thought I'd better double-check.
Is it expected that the alias
property is None
during field transformation? Has this something to do with the fact that the class is not yet fully built at this stage? But since all information is pretty much already available at this point, I'm wondering if this is unintended ... 🤔
from attrs import define, field, fields
def f(cls, x):
print("During field transformation:\n-------------------------------")
for y in x:
print(y.alias)
return x
@define(field_transformer=f)
class C:
_auto_stripped: int = field(default=0)
_auto_stripped_with_alias: int = field(default=0, alias="_auto_stripped_with_alias")
regular: int = field(default=0)
regular_with_alias: int = field(default=0, alias="regular_with_alias")
print("\nAfter class creation:\n-------------------------------")
for fld in fields(C):
print(fld.alias)
Gives:
During field transformation:
-------------------------------
None
_auto_stripped_with_alias
None
regular_with_alias
After class creation:
-------------------------------
auto_stripped
_auto_stripped_with_alias
regular
regular_with_alias
Metadata
Metadata
Assignees
Labels
No labels