On Mon, Feb 10, 2020 at 7:21 AM Soni L. <fakedme...@gmail.com> wrote:
>
> > Maybe if you had a good example that wasn’t an implicit type cast, this 
> > similarity would be an argument against using annotations rather than an 
> > argument for using them? But it’s hard to know without seeing such an 
> > example, or even knowing if you have such an example.
>
> That's C++. But consider this:
>
> class Foo:
>    def bar(self):
>      pass
>
> x = Foo()
> y = x.bar
>
> The traits thing is just as much of an implicit cast as Python methods
> are an implicit cast. Which is to say, it isn't. Traits don't have a
> constructor - instead, calling them with an object will, if the object
> allows it, create a wrapper object to handle the trait method lookups
> and any necessary wrapping or unwrapping of objects. This is also the
> way to access conflicting names: MyTrait(MyClass()).x() is defined in
> the @impl(MyTrait) (and does print("Hello,") then print("World!")),
> whereas MyClass().x() is the inherent method in MyClass (and only prints
> "World!"). Note also that the @impl gets the full unwrapped object, and
> not a TraitWrapper - this is by design.
>

This entire proposal is based on the need to disambiguate conflicting
method names, correct? Can you show any sort of example of something
where this is actually useful, and can't be better done with
composition rather than inheritance (since composition, in effect,
namespaces the methods - thing.trait1.x() and thing.trait2.x() rather
than multiply inheriting)? I'm having trouble wrapping my head around
the meaningful identities of the various different objects, since all
the examples use placeholder names with no true purpose.

And yes, I'm aware that what I'm asking for might end up too big for a
simple post. But it would be helpful to have a reference of some sort.

Chris
_______________________________________________
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/XEGUKWDLNJOSKBAIOCVK6QNG6S7V7OAR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to