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 reason (they're not).
On 2020-02-14 5:50 a.m., Neil Girdhar wrote:
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 -- python...@python.org <javascript:>
To unsubscribe send an email to python-id...@python.org <javascript:>
https://mail.python.org/mailman3/lists/python-ideas.python.org/
<https://mail.python.org/mailman3/lists/python-ideas.python.org/>
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/MMTEZRNSPHB55IYCKJ2E2CXDRN7KYURC/
<https://mail.python.org/archives/list/python-ideas@python.org/message/MMTEZRNSPHB55IYCKJ2E2CXDRN7KYURC/>
Code of Conduct: http://python.org/psf/codeofconduct/
<http://python.org/psf/codeofconduct/>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/F2MKZJ4QTGB7RC6JE4H3I3MTVAFMDU6T/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/W5KTZ6KQKNQQ4PGZI7ZZ7IJBFZWKO5AA/
Code of Conduct: http://python.org/psf/codeofconduct/