Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow attrs class object as input of attrs.fields #1400

Open
jxrossel opened this issue Jan 30, 2025 · 0 comments
Open

Allow attrs class object as input of attrs.fields #1400

jxrossel opened this issue Jan 30, 2025 · 0 comments
Labels

Comments

@jxrossel
Copy link

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

@hynek hynek added the Feature label Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants