Skip to content

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

Open
@jxrossel

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions