Skip to content

Add support for classmethod converters in attrs plugin #7912

Open
@tombo315

Description

@tombo315
import attr

@attr.s
class Bar:
    b = attr.ib()

    @classmethod
    def make(cls, one: int) -> 'Bar':
        return cls(one)


@attr.s
class Foo:
    a = attr.ib(converter=Bar.make)

error: Unsupported converter, only named functions and types are currently supported

Attrs is perfectly happy with make

>>> Foo(1)
Foo(a=Bar(b=1))

Granted the converter limitations are a known issue, I couldn't find this use-case covered anywhere.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions