You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That was me.
looking at source or attr make, it seems like this metadata is not currently maintained.
The reason I want this is because I am using attr (or dataclasses) as a template to generate an object that - among other things - performs runtime checks (type validation, recursive frozen check etc). This has some more context on what I am shooting for.
I was able to detect at runtime if a dataclass is frozen but was not able to do the same for attr classes.
FWIW, I find exposing more attrs-specific stuff onto classes to be problematic. That I use attrs is, to me, an implementation detail, and I don't intend "this is an attrs-built class" to be part of the interface to my classes.
The more attrs-specific introspection we add, the more locked-in to attrs classes become.
@wsanchez, I agree with the sentiment, but it should still be possible for someone who wants to do this introspection to do it reliably if they choose.
attrs and dataclasses have a pretty good feature parity already, so the any lock-in is minimal.
I am planning to support both in my library.
this specific thing is one of the things I feel more uncomfortable with right now.
defis_dataclass_frozen(type_):
returntype_.__dataclass_params__.frozendefis_attr_frozen(type_):
importattr# This is very hacky and probably fragile as well.# Unfortunately currently there isn't an official API in attr that can detect that.returntype_.__setattr__==attr._make._frozen_setattrs
Hmmm. So the thing is that I was kinda planning to expose class settings as a class internally anyway, because the amount of arguments is getting out of control.
However I plan too many internal changes soon-ish that I don't want to lo ourselves in rn.
Good to know about __dataclass_params__ – we should follow that naming convention if/once we implement it.
Wilfredo's argument is true but we always insisted on being extensible and allow introspection into attributes. It seems like a glaring omission to not allow introspection into the class itself.
I think I'll just pinky promise to not break your use case until we have an official API. ;)
Thanks @hynek.
Glad to hear you are planning on adding an official API for this.
I totally understand the desire to keep things as is until you have had some time to think and figure out what the best API is, especially with a major internal change in the horizon.
Thanks for pinky promising not to break my implementation until then! :)
Activity
omry commentedon Dec 2, 2019
That was me.
looking at source or attr make, it seems like this metadata is not currently maintained.
The reason I want this is because I am using attr (or dataclasses) as a template to generate an object that - among other things - performs runtime checks (type validation, recursive frozen check etc).
This has some more context on what I am shooting for.
I was able to detect at runtime if a dataclass is frozen but was not able to do the same for attr classes.
omry commentedon Dec 2, 2019
This seems to work, but it's very fragile:
It works if I import the class normally (from foo.bar import FrozenClass), but does not work when I import using import_module.
It would be great if there was a supported API to determine that (and possibly attr parameters).
wsanchez commentedon Dec 2, 2019
FWIW, I find exposing more
attrs-specific stuff onto classes to be problematic. That I useattrsis, to me, an implementation detail, and I don't intend "this is anattrs-built class" to be part of the interface to my classes.The more
attrs-specific introspection we add, the more locked-in toattrsclasses become.omry commentedon Dec 2, 2019
@wsanchez, I agree with the sentiment, but it should still be possible for someone who wants to do this introspection to do it reliably if they choose.
attrs and dataclasses have a pretty good feature parity already, so the any lock-in is minimal.
I am planning to support both in my library.
this specific thing is one of the things I feel more uncomfortable with right now.
hynek commentedon Dec 5, 2019
Hmmm. So the thing is that I was kinda planning to expose class settings as a class internally anyway, because the amount of arguments is getting out of control.
However I plan too many internal changes soon-ish that I don't want to lo ourselves in rn.
Good to know about
__dataclass_params__– we should follow that naming convention if/once we implement it.Wilfredo's argument is true but we always insisted on being extensible and allow introspection into attributes. It seems like a glaring omission to not allow introspection into the class itself.
I think I'll just pinky promise to not break your use case until we have an official API. ;)
omry commentedon Dec 5, 2019
Thanks @hynek.
Glad to hear you are planning on adding an official API for this.
I totally understand the desire to keep things as is until you have had some time to think and figure out what the best API is, especially with a major internal change in the horizon.
Thanks for pinky promising not to break my implementation until then! :)
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
3 remaining items
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Implement _AttrsParams
Expose effective class construction properties (#1454)
hynek commentedon Sep 30, 2025
This has now been fixed by #1454! 😮💨