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 NotImpl
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 whatever
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 attribute
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 Simionat
In Rust, you can have:
trait Foo {
fn x(&self);
}
trait Bar {
fn x(&self);
}
struct Baz {}
impl Foo for Baz {
fn x(&self) {
}
}
impl Bar for Baz {
fn x(&self) {
}
}
with strait, you can't have both Foo and Bar on Baz - it just raises by
default. if
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
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):
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 - it
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 su