Re: Python 3.9.14
On Wed, Sep 14, 2022 at 6:05 AM אורי wrote: > Hi, > > Python 3.9.14 has been released on Sept. 6, 2022. As I can see written on > https://www.python.org/downloads/release/python-3914/: > > According to the release calendar specified in PEP 596, Python 3.9 is now > in the "security fixes only" stage of its life cycle: the 3.9 branch only > accepts security fixes and releases of those are made irregularly in > source-only form until October 2025. Python 3.9 isn't receiving regular bug > fixes anymore, and binary installers are no longer provided for it. Python > 3.9.13 was the last full bugfix release of Python 3.9 with binary > installers. > > > Is there a safe way to install a 64-bit version of Python 3.9.14 on > Windows? > I use Windows as little as I can, but you could check to see if Conda or the Microsoft Store will give you CPython 3.9 binaries. If that isn't happening, you could try compiling your own from the python.org sources. On Linux, that's pretty simple: extract the archive, ./configure && make && sudo make install I don't know if it'll be easier or harder on WIndows. I want to say you could get MSYS2 as a development environment, but ISTR hearing that Python wants to be compiled with Microsoft's compiler on Windows for ABI compatibility. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to replace an instance method?
Here is an example of probably the easiest way to add an instance method: class Demo: def sqr(self, x): return x*x # Function to turn into a instance method def cube(self, x): return x*x*x d = Demo() print(d.sqr(2)) d.cube = cube.__get__(d) print(d.cube(3)) As for when someone might want to do this kind of thing, one place is when you are running scripts in an existing framework, and you can't change the class definition but you can access an instance. Or you might want to add the method to an existing class to debug and tune it up before you go through the formalities of actually changing an existing project. I once added a class to an running text editor so that it would highlight the current line. That was adding a class instead of a method, but the need was basically the same. On 9/16/2022 6:35 PM, Dan Stromberg wrote: On Fri, Sep 16, 2022 at 2:06 PM Ralf M. wrote: I would like to replace a method of an instance, but don't know how to do it properly. You appear to have a good answer, but... are you sure this is a good idea? It'll probably be confusing to future maintainers of this code, and I doubt static analyzers will like it either. I'm not the biggest fan of inheritance you'll ever meet, but maybe this is a good place for it? -- https://mail.python.org/mailman/listinfo/python-list
Re: How to replace an instance method?
On Fri, Sep 16, 2022 at 2:06 PM Ralf M. wrote: > I would like to replace a method of an instance, but don't know how to > do it properly. > You appear to have a good answer, but... are you sure this is a good idea? It'll probably be confusing to future maintainers of this code, and I doubt static analyzers will like it either. I'm not the biggest fan of inheritance you'll ever meet, but maybe this is a good place for it? -- https://mail.python.org/mailman/listinfo/python-list
Re: How to replace an instance method?
On 9/16/22, Ralf M. wrote: > I would like to replace a method of an instance, but don't know how to > do it properly. A function is a descriptor that binds to any object as a method. For example: >>> f = lambda self, x: self + x >>> o = 42 >>> m = f.__get__(o) >>> type(m) >>> m.__self__ is o True >>> m(10) 52 -- https://mail.python.org/mailman/listinfo/python-list
Re: How to replace an instance method?
On Sat, 17 Sept 2022 at 07:07, Ralf M. wrote: > > I would like to replace a method of an instance, but don't know how to > do it properly. > > My first naive idea was > > inst = SomeClass() > def new_method(self, param): > # do something > return whatever > inst.method = new_method > > however that doesn't work: self isn't passed as first parameter to > the new inst.method, instead inst.method behaves like a static method. > > I had a closer look at the decorators classmethod and staticmethod. > Unfortunetely I couldn't find a decorator / function "instancemethod" > that turns a normal function into an instancemethod. > > The classmethod documentation contains a reference to the standard > type hierarchie, and there is an explanation that an instancemethod > is sort of a dynamically created wrapper around a function, which > is accessable as __func__. > So I modified the last line of the example above to > > inst.method.__func__ = new_method > > but got told that __func__ is read only. > > I found some information about methods in the Descriptor HowTo Guide, > but it's about how it works internally and doesn't tell how to solve > my problem (at least it doesn't tell me). > > Now I'm running out of ideas what to try next or what sections of the > documentation to read next. > > Any ideas / pointers? > You don't actually want a descriptor, since the purpose of descriptor protocol is to give you information about the instance when the attribute (the method, in this case) was attached to the class. In this case, you can handle it with something far far simpler: inst.method = functools.partial(new_method, inst) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
How to replace an instance method?
I would like to replace a method of an instance, but don't know how to do it properly. My first naive idea was inst = SomeClass() def new_method(self, param): # do something return whatever inst.method = new_method however that doesn't work: self isn't passed as first parameter to the new inst.method, instead inst.method behaves like a static method. I had a closer look at the decorators classmethod and staticmethod. Unfortunetely I couldn't find a decorator / function "instancemethod" that turns a normal function into an instancemethod. The classmethod documentation contains a reference to the standard type hierarchie, and there is an explanation that an instancemethod is sort of a dynamically created wrapper around a function, which is accessable as __func__. So I modified the last line of the example above to inst.method.__func__ = new_method but got told that __func__ is read only. I found some information about methods in the Descriptor HowTo Guide, but it's about how it works internally and doesn't tell how to solve my problem (at least it doesn't tell me). Now I'm running out of ideas what to try next or what sections of the documentation to read next. Any ideas / pointers? Ralf M. -- https://mail.python.org/mailman/listinfo/python-list