[Python-ideas] Best practices of class "reopening" a-la Ruby?

2021-01-14 Thread Paul Sokolovsky
Hello, Ruby has following feature. Suppose the existing class "Cls" is scope (either defined before or imported from some module), then the code like: class Cls def mixin_method(args) ... end end Will "reopen" (Ruby term) that class and will add a new method "mixin_method" to it.

[Python-ideas] Re: Additional LRU cache introspection facilities

2021-01-14 Thread Steven D'Aprano
Okay, thanks everyone for the feedback. I accept that there are more practical difficulties than I expected, and the work-arounds I have are not too onerous. -- Steve ___ Python-ideas mailing list -- [email protected] To unsubscribe send an ema

[Python-ideas] Re: Best practices of class "reopening" a-la Ruby?

2021-01-14 Thread Chris Angelico
On Thu, Jan 14, 2021 at 10:07 PM Paul Sokolovsky wrote: > The question then: what are the best practices in *declarative* syntax > to achieve the same effect in Python? (but of course, unlike Ruby, > there should be explicit syntactic marker that we augment existing > class, not redefine it). Eas

[Python-ideas] Re: Best practices of class "reopening" a-la Ruby?

2021-01-14 Thread Steven D'Aprano
On Thu, Jan 14, 2021 at 02:05:50PM +0300, Paul Sokolovsky wrote: [...] > Semantically, Python can achieve the same with "imperative" syntax like: > > def mixin_method(self, args): > ... > Cls.mixin_method = mixin_method > > > The question then: what are the best practices in *declarative* s

[Python-ideas] Re: Best practices of class "reopening" a-la Ruby?

2021-01-14 Thread Paul Sokolovsky
Hello, On Thu, 14 Jan 2021 22:14:17 +1100 Chris Angelico wrote: > On Thu, Jan 14, 2021 at 10:07 PM Paul Sokolovsky > wrote: > > The question then: what are the best practices in *declarative* > > syntax to achieve the same effect in Python? (but of course, unlike > > Ruby, there should be expli

[Python-ideas] Re: Best practices of class "reopening" a-la Ruby?

2021-01-14 Thread Paul Sokolovsky
Hello, On Thu, 14 Jan 2021 22:19:06 +1100 Steven D'Aprano wrote: > On Thu, Jan 14, 2021 at 02:05:50PM +0300, Paul Sokolovsky wrote: > > [...] > > Semantically, Python can achieve the same with "imperative" syntax > > like: > > > > def mixin_method(self, args): > > ... > > Cls.mixin_method

[Python-ideas] Re: Best practices of class "reopening" a-la Ruby?

2021-01-14 Thread Ricky Teachey
You could also do this using just the __init_subclass__ method. Create some class AddMixin, and use it like: class _(AddMixin, using=mod.Cls): ... The AddMixin class is something like: class AddMixin: def __init_subclass_(cls, *, using, **kwargs): super().__init_subclass__(**kwar

[Python-ideas] Off-topic: What costs NaN pounds for a null amount?

2021-01-14 Thread Jonathan Fine
Hi There's interest here in arithmetic operations on NaN . I've just seen a product listed as costing NaN pounds to buy a null amount. That was written as £NaN/null. The bargain item is Glade Shake & Vacuum Citrus, and you can see it at https://www.tesco.com/groceries/en-GB/products/253732570 Se

[Python-ideas] Re: Off-topic: What costs NaN pounds for a null amount?

2021-01-14 Thread Barry Scott
> On 14 Jan 2021, at 17:14, Jonathan Fine wrote: > > Hi > > There's interest here in arithmetic operations on NaN . I've just seen a > product listed as costing NaN pounds to buy a null amount. That was written > as £NaN/null. > > The bargain item is Glade Shake & Vacuum Citrus, and you can