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 NotImplementedError
> def y(self):
> raise NotImplementedError
>
> trait Anoher:
> def x(self):
> raise NotImplementedError
> def y(self):
> raise NotImplementedError
>
> def foo(Trait(x)):
> x.x()
>
> class Bar:
> def y(self):
> print("hello")
> impl Trait:
> def x(self):
> self.y() # resolves to Bar.y
> impl Another:
> def x(self):
> raise ValueError
>
> foo(Bar()) # prints 'hello'
> Trait(Bar()).x() # also prints 'hello'
> Bar().x() # AttributeError: ambiguous reference to trait method x
>
> if the trait isn't used in the function definition you get the raw
> object, where name conflicts between traits (but not between traits and
> inherent methods) result in an error about name conflicts. otherwise you
> get a friendly wrapper.
> _______________________________________________
> Python-ideas mailing list -- [email protected] <javascript:>
> To unsubscribe send an email to [email protected] <javascript:>
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/MMTEZRNSPHB55IYCKJ2E2CXDRN7KYURC/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/F2MKZJ4QTGB7RC6JE4H3I3MTVAFMDU6T/
Code of Conduct: http://python.org/psf/codeofconduct/