attrs icon indicating copy to clipboard operation
attrs copied to clipboard

Allow attrs class object as input of attrs.fields

Open jxrossel opened this issue 10 months ago • 0 comments

Unless I am mistaken, one cannot use attrs.fields on a attrs class object, unlike attrs.has. The workaround is simple, either attrs.fields(type(obj)) or obj.__attrs_attrs__. It would be nice to be able to use attrs.fields directly.


@attrs.define
class Hello():
    a = attrs.field()
    b = attrs.field()

# This works
attrs.fields(Hello)

# But this doesn't (yet)
attrs.fields(Hello(1, 2))

# NB: this works though
attrs.has(Hello)
attrs.has(Hello(1, 2))

Thanks for the awesome library

jxrossel avatar Jan 30 '25 09:01 jxrossel