[Python-ideas] Re: Curious : Why staticmethod if classmethods can do everything a static method can?

2020-09-12 Thread Steven D'Aprano
On Sun, Sep 13, 2020 at 12:32:54AM -0400, Random832 wrote: > This isn't what I was suggesting - I meant something like this: > > class instancemethod: > def __init__(self, wrapped): > self.wrapped = wrapped > def __get__(self, obj, objtype): > if obj is None: return self.w

[Python-ideas] Re: Curious : Why staticmethod if classmethods can do everything a static method can?

2020-09-12 Thread Random832
On Sat, Sep 12, 2020, at 23:14, Steven D'Aprano wrote: > We already have an instancemethod, it's just spelled differently: > > py> from types import MethodType > > > And while it is not useful as a decorator, it is *really* useful for > adding methods to an individual instance rather than t

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Steve Barnes
Indeed the usual definition of isnan reads: def isnan(x): return x != x ___ 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.p

[Python-ideas] Re: Curious : Why staticmethod if classmethods can do everything a static method can?

2020-09-12 Thread Steven D'Aprano
On Sat, Sep 12, 2020 at 07:25:30PM -0400, Eric V. Smith wrote: > On 9/12/2020 7:13 PM, Random832 wrote: > >On Fri, Sep 11, 2020, at 19:57, Cameron Simpson wrote: > >>The default (an instance method) requires "self" to perform. > >Of course, this is only the default if the method is a function objec

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Steven D'Aprano
On Sat, Sep 12, 2020 at 02:09:11PM -1000, David Mertz wrote: > On Sat, Sep 12, 2020, 2:02 PM Steven D'Aprano wrote: > > > In general though, Python doesn't support generating the full range of > > NANs with payloads directly. > > > I've researched this a little bit for discussion in a book I'm

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Steven D'Aprano
On Sat, Sep 12, 2020 at 05:37:23PM -0700, Christopher Barker wrote: > On Sat, Sep 12, 2020 at 5:05 PM Steven D'Aprano wrote: > > IEEE-754 requires that float literals overflow to infinity. > > sure, which means that, e.g. 1e100 * 1e300 would overflow to Inf. > > But that doesn't say anything a

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Richard Damon
On 9/12/20 8:48 PM, Paul Bryan wrote: > I meant to ask, why is nan not comparable? Even: > > >>> math.nan == math.nan > False It's the IEEE definition of nan, a nan will compare unequal to ALL values, even another nan. It is also neither greater than or less than any value. -- Richard Damon ___

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Paul Bryan
I meant to ask, why is nan not comparable? Even: >>> math.nan == math.nan False ___ 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.py

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Paul Bryan
On Sun, 2020-09-13 at 10:01 +1000, Steven D'Aprano wrote: > If you have an INF, then you can generate a NAN with `INF - INF`. >>> math.inf - math.inf nan >>> (math.inf - math.inf) == math.nan False ___ Python-ideas mailing list -- python-ideas@pytho

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Christopher Barker
On Sat, Sep 12, 2020 at 5:05 PM Steven D'Aprano wrote: > On Sat, Sep 12, 2020 at 12:56:25PM -0700, Christopher Barker wrote: > > > Is there any guarantee in Python or the C spec, or the IEEE spec that, > e.g.: > > 1e1 > > would create an Inf value, rather than an error of some sort? > > IEEE-

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread David Mertz
I probably should have added "user exposed" or something to my comment. Those extra bits certainly seem to offer compiler optimization possibilities, as apparently SpiderMonkey does with WASM. I can easily *imagine* a library like NumPy or PyTorch deciding to expose something useful with those 52

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Cade Brown
As per tagged nans, check for JavaScript tagged NaN optimization. Essentially, the tag of the NaN (i.e. the mantissa) is interpreted as a pointer. Obviously, this is a very advanced use case, probably not worth Python guaranteeing such behavior. Here is one article: https://brionv.com/log/2018/05/1

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread David Mertz
On Sat, Sep 12, 2020, 2:02 PM Steven D'Aprano wrote: > In general though, Python doesn't support generating the full range of > NANs with payloads directly. I've researched this a little bit for discussion in a book I'm writing, and I have not been able to identify ANY widely used programming l

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Steven D'Aprano
On Sat, Sep 12, 2020 at 12:56:25PM -0700, Christopher Barker wrote: > Is there any guarantee in Python or the C spec, or the IEEE spec that, e.g.: > > 1e1 > > would create an Inf value, rather than an error of some sort? IEEE-754 requires that float literals overflow to infinity. I don't h

[Python-ideas] Re: Curious : Why staticmethod if classmethods can do everything a static method can?

2020-09-12 Thread Eric V. Smith
On 9/12/2020 7:13 PM, Random832 wrote: On Fri, Sep 11, 2020, at 19:57, Cameron Simpson wrote: The default (an instance method) requires "self" to perform. Of course, this is only the default if the method is a function object. If it is a different callable class, the default is effectively sta

[Python-ideas] Re: Curious : Why staticmethod if classmethods can do everything a static method can?

2020-09-12 Thread Random832
On Fri, Sep 11, 2020, at 19:57, Cameron Simpson wrote: > The default (an instance method) requires "self" to perform. Of course, this is only the default if the method is a function object. If it is a different callable class, the default is effectively staticmethod. Perhaps there should be an @

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Christopher Barker
not really relevant anyway, but the issue with using a really large literal to get Infinity is not that some possible future system could hold really huge numbers, but whether a too-large-for-the-implimentation literal get evaluated as Inf at all. Is there any guarantee in Python or the C spec, or

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-12 Thread Christopher Barker
On Sat, Sep 12, 2020 at 1:40 AM Serhiy Storchaka wrote: > Second, the resulting function would have monstrous interface. open() > takes 8 arguments, well, maybe not -- this would not need to support the entire open() interface: * No one is suggesting getting rid of the current load() function,

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-12 Thread Christopher Barker
On Sat, Sep 12, 2020 at 5:29 AM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > See Naoki Inada's post for why this might be a good idea even though > it's a three-line function. It's not open and shut (for one thing, on > most modern systems the system default encoding is alr

[Python-ideas] Re: Curious : Why staticmethod if classmethods can do everything a static method can?

2020-09-12 Thread Ethan Furman
On 9/11/20 7:35 PM, Christopher Barker wrote: - > But the real question is why staticmethod at all? > > And the answer is that there is very little use for staticmethod in > Python [...] On 9/11/20 7:28 PM, Greg Ewing wrote: ---

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Steven D'Aprano
On Sat, Sep 12, 2020 at 11:06:35AM -0400, Cade Brown wrote: > If, in the future, Python used a library such as MPFR and made all floats a > given precision (say, by giving a flag to the interpreter "python > -prec2048"), it would never be enough to make infinity because it only has > the limitation

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-12 Thread Edwin Zimmerman
On 9/12/2020 12:05 PM, Greg Ewing wrote: > On 12/09/20 8:36 pm, Serhiy Storchaka wrote: >> it is not hard to write your >> own helper with interface and defaults that suit you. It will take less >> time than writing a letter in a mailing list. > > Obviously what's needed is an IDE feature such th

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-12 Thread Greg Ewing
On 12/09/20 8:36 pm, Serhiy Storchaka wrote: it is not hard to write your own helper with interface and defaults that suit you. It will take less time than writing a letter in a mailing list. Obviously what's needed is an IDE feature such that whenever you write a 3-line function that you haven

[Python-ideas] Re: Curious : Why staticmethod if classmethods can do everything a static method can?

2020-09-12 Thread 2QdxY4RzWzUUiLuE
On 2020-09-12 at 14:07:57 +1000, Cameron Simpson wrote: > Dan, I should preface this by saying I don't substantially disagree > with you, I just work differently and want to show how and why. > The beauty here is that you have the same pattern of > classname.transcribe_value(value) to use whatev

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Cade Brown
If, in the future, Python used a library such as MPFR and made all floats a given precision (say, by giving a flag to the interpreter "python -prec2048"), it would never be enough to make infinity because it only has the limitation of a 64 bit exponent. This is just an example of course, probably

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-12 Thread Stephen J. Turnbull
The Nomadic Coder writes: > This came out personal frustration, as I use this 3 line function > very, very often, and the whole community does. I don't deny your experience, but mine differs. Most JSON I get as single objects arrives as strings (eg as an attribute on an HTTP response object),

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Stephen J. Turnbull
Guido van Rossum writes: > I don't actually understand why Stephen made this claim about > arithmetic operations, Stephen is often mistaken about computers (among many topics). That's why he mostly posts on -ideas, and mostly throws drafts away rather than post them. :-) I would not claim tha

[Python-ideas] Re: 'Infinity' constant in Python

2020-09-12 Thread Steven D'Aprano
On Fri, Sep 11, 2020 at 11:19:05AM -1000, David Mertz wrote: > On Fri, Sep 11, 2020 at 10:19 AM Guido van Rossum wrote: > > > While one may argue that writing `1e1000` is not an "arithmetic > > operation", certainly it's certainly not "casting strings to floats", and > > it's the simeplest way of

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-12 Thread Serhiy Storchaka
11.09.20 23:28, The Nomadic Coder пише: > Hi All, > > This is the first time I'm posting to this mailing group, so forgive me if > I'm making any mistakes. > > So one of the most common ways to load json, is via a file. This is used > extensively in data science and the lines. We often write so

[Python-ideas] Re: A shortcut to load a JSON file into a dict : json.loadf

2020-09-12 Thread Serhiy Storchaka
12.09.20 01:57, Guido van Rossum пише: > What happened to "not every three-line function needs to be a built-in"? > This is *literally* a three-line function. And I know the proposal is > not to make it a builtin, but still... ISTM down here lies the path to PHP. Oh, I am very glad that this princ