[Python-ideas] Add a decorators called @staticproperty

2021-12-18 Thread me
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 "". It might be a good idea to use "@staticproperty" to solve this problem. "@staticprope

[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 a

[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 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 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: set arbitrary hash random seed to ensure reproducible results

2021-12-18 Thread Hao Hu
On 12/18/21 08:44, Stephen J. Turnbull wrote: Hao Hu writes: > > On 17 Dec 2021, at 15:28, Chris Angelico wrote: > > The built-in hash() function is extremely generic, so it can't really > > work that way. Adding a parameter to it would require (a) adding the > > parameter to every __h

[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, Christoph

[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 > > a

[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. __