[Python-Dev] Descriptors in dataclasses fields

2021-01-03 Thread Josue Balandrano Coronel
I've been exploring dataclasses for a few months now and they've proven to be very useful. The only downside is that there's not a simple way to use descriptors. Descriptors only work on class attributes (as per the docs: https://docs.python.org/3/howto/descriptor.html#closing-thoughts). This m

[Python-Dev] Re: Descriptors in dataclasses fields

2021-01-04 Thread Josue Balandrano Coronel
the attribute will actually hold - mypy should not complain: > ``` > @dataclass > class Item: > price: Decimal = typing.cast(Decimal, MyDescriptor()) > > ``` > > On Sun, 3 Jan 2021 at 22:48, Josue Balandrano Coronel > wrote: > > I've been exploring dataclasses for a fe

[Python-Dev] Re: Descriptors in dataclasses fields

2021-01-04 Thread Josue Balandrano Coronel
Then this is more of an issue with type hints rather than dataclasses. Interesting. On Mon, Jan 4, 2021, at 16:01, Josue Balandrano Coronel wrote: > Ah, very interesting. > > Just tried this and it worked. That's awesome, thanks! > > On Mon, Jan 4, 2021, at 15:45, Joao S. O