python redefining `attrs.field` to accept default argument

62 Views Asked by At

How do you redefine the attrs.field function (and type hint it) to accept a default argument? This is my current code.

from attrs import define, field


def fixed_attr(default, **kwargs):
    return field(default=default, repr=False, init=False, eq=False, **kwargs)

@define
class A:
    number: int = fixed_attr(10)

Should I use Literal[10] instead of int? Do I need to type hint the output of fixed_attr? Why do my type hinter (pylance/pyright) still show number as an argument?

0

There are 0 best solutions below