Hence why I said 'would', 'if' etc. And it was brought up/suggested, having singletons. It does naturally flow from having a built-in (much like having singletons for booleans does):
sugggesting that one reason that they were made keywords is that it's > useful for them to be singletons, which is much harder to do (or at least > use consistently) if the names can be reassigned. > But these float special values can't be singletons anyway -- they could > come from anywhere, so you really don't want to have people doing: > (to be honest, to me it does make sense to have 'inf' singletons, but not for 'nan's. but, neither is part of the PEP). 'inf' is a very special value, and there are only 2 infinite floats (inf, -inf). Having a singleton is useful also perhaps as a memory optimization (i.e. whenever creating a float from C, check if it is infinite, and if so, return a new reference to the global inf/-inf variable). Again, this is not part of the PEP, so I don't think we want to spend much time discussing whether they should be singletons. For now, the answer seems to be: no Thanks, ---- *Cade Brown* Research Assistant @ ICL (Innovative Computing Laboratory) Personal Email: brown.c...@gmail.com ICL/College Email: c...@utk.edu On Sun, Sep 13, 2020 at 10:19 PM Chris Angelico <ros...@gmail.com> wrote: > On Mon, Sep 14, 2020 at 11:05 AM Cade Brown <brown.c...@gmail.com> wrote: > > This would become relevant, if, say Python 4.0 migrated 'inf' and 'nan' > to builtin names (like True and False). If that happened, a 'nan' singleton > wouldn't make sense unless you had 2**53 of them, so code like: > > > > >>> x is nan > > > > Would be a flawed formulation > > > > Nobody's suggesting that they become keywords representing singletons, > which is what True and False are. (At least, I don't think so.) What's > being proposed is simply a builtin name that has a value of > float("inf"). People don't write "x is 1.5" and they shouldn't use "x > is inf". It doesn't matter that there are multiple bit patterns that > represent nan; you shouldn't be doing this even when there's only one > bit pattern for the value. Yes, sometimes people do this with small > integers, and in CPython it may work ("x is 5" will usually be true > for any integer 5), but it's just as buggy there and I don't think > that's particularly relevant. > > (How often do people even use "x is True"?) > > ChrisA > _______________________________________________ > 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/PAQQ4J6YHRB6B7HTCR6IQQ2EZN32SOCE/ > 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/KFTJJT6A45YCJBXSB2E7ICVFGBZ3MS3D/ Code of Conduct: http://python.org/psf/codeofconduct/