[Python-ideas] Re: Add a decorators called @staticproperty

2021-12-19 Thread Christopher Barker
On Sun, Dec 19, 2021 at 5:41 AM Serhiy Storchaka wrote: So you can use a combination of @classmethod and @property. > > class Data: > @classmethod > @property > def imagesTotal(cls): > return 10 And this would be more useful anyway: if you want a class property, it may well

[Python-ideas] Re: Add a decorators called @staticproperty

2021-12-19 Thread Serhiy Storchaka
18.12.21 13:18, m...@chenjt.com пише: > It might be a good idea to use "@staticproperty" to solve this problem. > "@staticproperty" is a decorators, it mix the @staticmethod and @property. > Then the static property has getter and setter. classmethod supersedes staticmethod. It was not clearly

[Python-ideas] Re: Add a decorators called @staticproperty

2021-12-18 Thread Chen Jintao
Thank everyone! I just want to use a class that holds global variables and has a value that can be easily calculated. So I thought it would be more elegant to use "@staticproperty". These is just my personal thought and not necessary. Now you've given me the solution.

[Python-ideas] Re: Add a decorators called @staticproperty

2021-12-18 Thread Chris Angelico
On Sun, Dec 19, 2021 at 8:10 AM Ethan Furman wrote: > > By way of correcting misconceptions: > > On 12/18/21 8:39 AM, Chris Angelico wrote: > > > > I'm not sure that this is actually possible the way you're doing it. > > The descriptor protocol (which is what makes properties work) won't > >

[Python-ideas] Re: Add a decorators called @staticproperty

2021-12-18 Thread Ethan Furman
By way of correcting misconceptions: On 12/18/21 8:39 AM, Chris Angelico wrote: > > I'm not sure that this is actually possible the way you're doing it. > The descriptor protocol (which is what makes properties work) won't > apply when you're looking up statically. On 12/18/21 9:19 AM,

[Python-ideas] Re: Add a decorators called @staticproperty

2021-12-18 Thread Danilo J. S. Bellini
If the goal is to create a "property" that behaves like such but doesn't receive "self" as a parameter, the straightforward way to do so would be a simple descriptor. class StaticProperty: def __init__(self, fget=None, fset=None, fdel=None): self.fget = fget self.fset = fset

[Python-ideas] Re: Add a decorators called @staticproperty

2021-12-18 Thread Joao S. O. Bueno
All that is needed is a descriptor which calls the decorated functiosn without any parameters. This could serve to use classes as namespaces for "live" globals - if one will do some sort of reactive programing, it might even find some use. A descriptor with a for that would be something like:

[Python-ideas] Re: Add a decorators called @staticproperty

2021-12-18 Thread Christopher Barker
I'm confused about what a staticproperty would even be. Usually, properties are a way to provide an interface that "looks like" a simple attribute, but does some computation under the hood. But that computation usually requires instance data to do its thing -- so a static one wouldn't be useful.

[Python-ideas] Re: Add a decorators called @staticproperty

2021-12-18 Thread Chris Angelico
On Sun, Dec 19, 2021 at 3:31 AM wrote: > > In the following situations: > > > class Data(object): > @staticmethod > @property > def imagesTotal(): > return 10 > > print(Data.imagesTotal) > > > The "print(Data.imagesTotal)" can't print "10", it print " 0x...>". > > It might be