1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Is there a decorator for attrs factory sugar?

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    Similar to Decorator for attrs converter, please see this case:

    from attrs import define, field, Factory

    @define
    class MyClass:
    name = field(default = Factory(_name_factory, takes_self=True), init=False)

    @name.default # or @name.factory
    def _name_factory():
    return "standard name" # this would be a much more complicated function of course

    ERROR: x.py - NameError: name '_name_factory' is not defined


    Is there a decorator that would let the name be visible? I am trying to understand the documentation, but I am having issues.

    Continue reading...

Compartilhe esta Página