[Python-ideas] Re: Traits

2020-02-14 Thread Soni L.
On 2020-02-14 11:42 p.m., Steven D'Aprano wrote: On Fri, Feb 14, 2020 at 07:24:48PM -0300, Soni L. wrote: > In Rust, you can have: That's great for people who understand both Rust styntax and Rust semantics, but this is a Python discussion group, not Rust. We aren't all Rust experts. I do

[Python-ideas] Re: Traits

2020-02-14 Thread Steven D'Aprano
On Fri, Feb 14, 2020 at 07:24:48PM -0300, Soni L. wrote: > In Rust, you can have: That's great for people who understand both Rust styntax and Rust semantics, but this is a Python discussion group, not Rust. We aren't all Rust experts. > with strait, you can't have both Foo and Bar on Baz -

[Python-ideas] Re: Traits

2020-02-14 Thread Ethan Furman
On 02/14/2020 02:24 PM, Soni L. wrote:   class Foo(Trait):     def x(self):   raise NotImplementedError   class Bar(Trait):     def x(self):   raise NotImplementedError   class Baz(TraitObject):  # "mirrors" class Baz(object):     @impl(Foo)     class Foo:   def x(self):

[Python-ideas] Re: Traits

2020-02-14 Thread Chris Angelico
On Sat, Feb 15, 2020 at 9:25 AM Soni L. wrote: > the function explicitly calls the trait method on the object: > >obj = Baz(); >Bar(obj).x() # or Baz.Bar.x(obj) if you know the name under which > the trait impl is located and wanna use it rather than making a wrapper > trait object. And

[Python-ideas] Re: Traits

2020-02-14 Thread Soni L.
In Rust, you can have:   trait Foo {     fn x();   }   trait Bar {     fn x();   }   struct Baz {}   impl Foo for Baz {     fn x() {     }   }   impl Bar for Baz {     fn x() {     }   } with strait, you can't have both Foo and Bar on Baz - it just raises by default. if you don't want it

[Python-ideas] Re: Traits

2020-02-14 Thread Steven D'Aprano
On Fri, Feb 14, 2020 at 09:53:27AM -0300, Soni L. wrote: > Nobody has implemented actual > traits in Python yet, only mixins with extra steps That's a bold claim, since the meaning of "traits" you gave earlier in the thread sounded to me exactly like "mixins with extra steps". Michele

[Python-ideas] Re: Traits

2020-02-14 Thread Ethan Furman
On 02/14/2020 04:53 AM, Soni L. wrote: That's not traits. That's its own thing. That's not even mixins, it just seems to be type-checked attributes. Nobody has implemented actual traits in Python yet, only mixins with extra steps and there are 2 libraries providing these type-checked

[Python-ideas] Re: Traits

2020-02-14 Thread Soni L.
That's not traits. That's its own thing. That's not even mixins, it just seems to be type-checked attributes. Nobody has implemented actual traits in Python yet, only mixins with extra steps and there are 2 libraries providing these type-checked attributes and calling them "traits" for

[Python-ideas] Re: Traits

2020-02-14 Thread Neil Girdhar
You may be interested in the excellent traitlets library: https://traitlets.readthedocs.io/en/stable/ On Friday, February 7, 2020 at 11:11:59 AM UTC-5, Soni L. wrote: > > I'd like to see traits some day, with a syntax similar to this one: > > trait Trait: >def x(self): > raise