On Tue, 12 Jul 2022, 18:05 Steve Jorgensen, <stevec...@gmail.com> 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. 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 22:53, Steve Jorgensen stevec...@gmail.com 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. > > > It is usually considered a code smell to have a class that is two or > more > > > things. > > > This seems to be what you are trying to do. > > > How can one class be a set of fields and also the enum for one of its > own > > > fields? > > > I do not understand why this is resonable. > > > Barry > > > Python-ideas mailing list -- python-ideas@python.org > > > To unsubscribe send an email to python-ideas-le...@python.org > > > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > > > Message archived at > > > > https://mail.python.org/archives/list/python-ideas@python.org/message/V6U7UM. > .. > > > Code of Conduct: http://python.org/psf/codeofconduct/ > > > Python-ideas mailing list -- python-ideas@python.org > > > To unsubscribe send an email to python-ideas-le...@python.org > > > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > > > Message archived at > > > > https://mail.python.org/archives/list/python-ideas@python.org/message/HZFZE3. > .. > > > Code of Conduct: http://python.org/psf/codeofconduct/ > > > -- > > > Keeping medicines from the bloodstreams of the sick; food > > > from the bellies of the hungry; books from the hands of the > > > uneducated; technology from the underdeveloped; and putting > > > advocates of freedom in prisons. Intellectual property is > > > to the 21st century what the slave trade was to the 16th. > > > Sorry, I don't know how I communicated that I was trying to have one > class be a set of fields and also the enum for one of its own fields. > > > I'm really just wanting to have each member of the enum be an instance > of a frozen dataclass. If an of the dataclass fields were of an enum type, > then it would presumably not be for the same enum. In my example, none of > the fields of the dataclass contains an enum. One contains a string, and > the other contains an int. > > > Just throwing an idea out there, but would it work better to have an > > enum-namedtuple instead? > > ChrisA > > The only benefit I can think of for namedtuple vs a dataclass is > compactness in memory, but the number of members of an enum is typically > very small. I think the extra flexibility of a dataclass makes more > desirable for this purpose. > The ability to unpack a namedtuple as an iterable is considered to be a great advantage the dataclass has over the named tuple because changing the number of members is a backwards incompatible change for namedtuple. No reason in principle why a frozen dataclass should be less memory efficient than a namedtuple (?). Michael _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/F4YM66UAQ3GXXBIMPNX6MLEQA22K7UVL/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/DJU32XDG2HDHQAEQN2H5KTRABCXLWUYY/ Code of Conduct: http://python.org/psf/codeofconduct/