[Python-ideas] Re: Confusing naming of Optional type should be changed
Kevin Mills writes: > While confusion with optional arguments is somewhat unfortunate, > the name came from an already established convention. A lot of > languages have exactly the same concept, varying between names like > Optional, Option, and Maybe. I don't think coming up with a > Python-specific name for the same thing is necessarily better. This seems likely to be more or less moot. If you're interested, see Guido's (!!) new PEP 695 (pretty sure that's the number, need to go to meeting that is starting, sorry). > > Of course, it's immaterial now that the union syntax is preferred. > ___ > 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/4IAHIQ4V6UOGH2AJX46KWTXVBUJEP3MJ/ > 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/FDTTV5Q7LSN3MAJGAUWPQ64Z4HULS7LX/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Make dataclass aware that it might be used with Enum
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. 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/
[Python-ideas] Re: Confusing naming of Optional type should be changed
While confusion with optional arguments is somewhat unfortunate, the name came from an already established convention. A lot of languages have exactly the same concept, varying between names like Optional, Option, and Maybe. I don't think coming up with a Python-specific name for the same thing is necessarily better. Of course, it's immaterial now that the union syntax is preferred. ___ 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/4IAHIQ4V6UOGH2AJX46KWTXVBUJEP3MJ/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Make dataclass aware that it might be used with Enum
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. ___ 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] Re: Make dataclass aware that it might be used with Enum
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 an example like this to the documentation for `Enum`. > > In [1]: from dataclasses import dataclass > > In [2]: from enum import Enum > > In [3]: @dataclass(frozen=True) >...: class CreatureDataMixin: >...: size: str >...: legs: int >...: > > In [4]: class Creature(CreatureDataMixin, Enum): >...: BEETLE = ('small', 6) >...: DOG = ('medium', 4) >...: > > In [5]: Creature.DOG > Out[5]: Creature(size='medium', legs=4) > I really like this example. I love dataclasses and I love enums and it looks like they go together like peanut butter and chocolate.You get a free initialiser (__init__ method) and all the other goodness of dataclasses (which are really very good). I tweeted your example and it got 29 likes :-) https://twitter.com/voidspace/status/1546832332056924161 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/G2VALQ4RIVFKIOKVW4XZAHZMLSZWL2XS/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Michael Foord Python Consultant, Contractor and Trainer https://agileabstractions.com/ ___ 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/DZ73MVKZSWJE7ADUZFZ7NKJUAFPRTKWE/ Code of Conduct: http://python.org/psf/codeofconduct/