[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-20 Thread Steve Jorgensen
Ethan Furman wrote: > On 7/9/22 12:19, Steve Jorgensen wrote: > > [...] It works great to combine them by defining the dataclass as a mixin > > for the Enum class. Why would > > it not be good to include that as an example in the official docs, assuming > > (as I believe) that it is a > >

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-18 Thread Ethan Furman
On 7/9/22 12:19, Steve Jorgensen wrote: > [...] It works great to combine them by defining the dataclass as a mixin for the Enum class. Why would > it not be good to include that as an example in the official docs, assuming (as I believe) that it is a > particularly useful combination? Do you

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-17 Thread Ethan Furman
On 7/7/22 18:22, Steve Jorgensen wrote: > After some playing around, I figured out a pattern that works without any changes to the > implementations of `dataclass` or `Enum`, and I like this because it keeps the 2 kinds of > concern separate. Maybe I'll try submitting an MR to add an example

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-17 Thread Ethan Furman
On 7/8/22 19:50, Ethan Furman wrote: > The repr from a combined dataclass/enum looks like a dataclass, giving no clue that the > object is an enum, and omitting any information about which enum member it is and which > enum it is from. Fixed in 3.11: `` -- ~Ethan~

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-17 Thread Ethan Furman
On 7/7/22 09:01, Steve Jorgensen wrote: > Actually, maybe these are fundamentally incompatible? `@dataclass` is a decorator, so it > acts on the class after it was already defined, but `Enum` acts before that when `@dataclass` > cannot have not generated the `__init__` yet. Right? Correct.

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-17 Thread Ethan Furman
On 7/6/22 17:01, Steve Jorgensen wrote: > Perhaps, this has already been addressed in a newer release (?) but in Python 3.9, making > `@dataclass` work with `Enum` is a bit awkward. > > Currently, it order to make it work, I have to: > 1. Pass `init=False` to `@dataclass` and hand-write the

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-12 Thread Michael Foord
On Tue, 12 Jul 2022, 18:05 Steve Jorgensen, wrote: > Chris Angelico wrote: > > On Mon, 11 Jul 2022 at 03:54, Steve Jorgensen stevec...@gmail.com wrote: > > > David Mertz, Ph.D. wrote: > > > I've seen this thread, and also wondered why anyone could EVER want a > > > dataclass that is an enum.

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-12 Thread Steve Jorgensen
Chris Angelico wrote: > On Mon, 11 Jul 2022 at 03:54, Steve Jorgensen stevec...@gmail.com wrote: > > David Mertz, Ph.D. wrote: > > I've seen this thread, and also wondered why anyone could EVER want a > > dataclass that is an enum. Nothing I've seen in the thread gives me any > > hint about that,

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-12 Thread Michael Foord
On Fri, 8 Jul 2022 at 02:22, Steve Jorgensen wrote: > After some playing around, I figured out a pattern that works without any > changes to the implementations of `dataclass` or `Enum`, and I like this > because it keeps the 2 kinds of concern separate. Maybe I'll try submitting > an MR to add

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-10 Thread Chris Angelico
On Mon, 11 Jul 2022 at 03:54, Steve Jorgensen wrote: > > David Mertz, Ph.D. wrote: > > I've seen this thread, and also wondered why anyone could EVER want a > > dataclass that is an enum. Nothing I've seen in the thread gives me any > > hint about that, really. > > On Sun, Jul 10, 2022 at 7:44

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-10 Thread Steve Jorgensen
David Mertz, Ph.D. wrote: > I've seen this thread, and also wondered why anyone could EVER want a > dataclass that is an enum. Nothing I've seen in the thread gives me any > hint about that, really. > On Sun, Jul 10, 2022 at 7:44 AM Barry Scott ba...@barrys-emacs.org wrote: > > On 9 Jul 2022, at

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-10 Thread David Mertz, Ph.D.
I've seen this thread, and also wondered why anyone could EVER want a dataclass that is an enum. Nothing I've seen in the thread gives me any hint about that, really. On Sun, Jul 10, 2022 at 7:44 AM Barry Scott wrote: > > > > On 9 Jul 2022, at 22:53, Steve Jorgensen wrote: > > > > I don't

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-10 Thread Barry Scott
> On 9 Jul 2022, at 22:53, Steve Jorgensen wrote: > > I don't think that dataclasses have the limited set of intended uses that you > are interpreting them as having. To me, the fact that they can be frozen > makes them a good fit with Enum. Please quote the email that you are replying to.

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-09 Thread Steve Jorgensen
I don't think that dataclasses have the limited set of intended uses that you are interpreting them as having. To me, the fact that they can be frozen makes them a good fit with Enum. ___ Python-ideas mailing list -- python-ideas@python.org To

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-09 Thread Steve Jorgensen
Ethan Furman wrote: > On 7/7/22 09:01, Steve Jorgensen wrote: > > Actually, maybe these are fundamentally incompatible? > > Their intended use seems fundamentally incompatible: > - dataclass was designed for making many mutable records (hundreds, > thousands, or more) > - enum was designed to

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-08 Thread Ethan Furman
On 7/7/22 09:01, Steve Jorgensen wrote: > Actually, maybe these are fundamentally incompatible? Their intended use seems fundamentally incompatible: - dataclass was designed for making many mutable records (hundreds, thousands, or more) - enum was designed to make a handful of named constants

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-08 Thread Barry Scott
> On 8 Jul 2022, at 02:22, Steve Jorgensen wrote: > > After some playing around, I figured out a pattern that works without any > changes to the implementations of `dataclass` or `Enum`, and I like this > because it keeps the 2 kinds of concern separate. Maybe I'll try submitting > an MR

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-07 Thread Steve Jorgensen
After some playing around, I figured out a pattern that works without any changes to the implementations of `dataclass` or `Enum`, and I like this because it keeps the 2 kinds of concern separate. Maybe I'll try submitting an MR to add an example like this to the documentation for `Enum`. In

[Python-ideas] Re: Make dataclass aware that it might be used with Enum

2022-07-07 Thread Steve Jorgensen
Steve Jorgensen wrote: > Perhaps, this has already been addressed in a newer release (?) but in Python > 3.9, making `@dataclass` work with `Enum` is a bit awkward. > Currently, it order to make it work, I have to: > 1. Pass `init=False` to `@dataclass` and hand-write the `__init__` method > 2.