[Python-ideas] Optional Static Typing -- the Python Way
Brett Cannon
brett at python.org
Fri Aug 22 14:53:25 CEST 2014
On Thu Aug 21 2014 at 10:55:47 AM Antoine Pitrou <antoine at python.org> wrote:
>
> Le 21/08/2014 10:30, Brett Cannon a écrit :
> >
> > Isn't that the magic of __instancecheck__/__subclasscheck__? If
> > typing.py does the right thing here then it shouldn't matter.
>
> What is "the right thing"?
>
I don't feel like scrolling all the way back through this thread to find
your original email, but "the right thing" is "whatever it takes". =) My
point is that I don't think there is any technical reason why we can't make
ABCs work.
>
> > You could
> > use __init__ or __getitem__ to construct an object who upon
> > introspection provides the details you want and do what you expect, and
> > then override the appropriate methods so that isinstance() checks check
> > against the ABC instead of the type class itself (heck we could make the
> > base type class require that you inherit from an ABC to promote working
> > with ABCs instead of concrete classes).
>
> So we agree that type descriptions should be separate things from ABCs,
> or not?
>
We don't agree. I'm fine with reusing ABCs. My only point is that if you
really don't want to tweak ABCs to work directly, typing.py can still use
ABCs as a subclass and then add whatever is necessary on top of them.
>
> > I have to also say that I like using ABCs because `from collections
> > import abc as a` leads to reading parameters like "x is a.Mapping" which
> > is linguistically quaint. =)
>
> Except that "x is a.Mapping" is False with a normal Python.
>
You're reading that too literally as code and not as a descriptive
sentence. What I meant to convey is that code `def foo(x: a.Mapping)` can
be read in your inner voice as "function foo has a parameter x which is
a.Mapping", where "a.Mapping" somewhat reads like "a Mapping".
-Brett
>
> Regards
>
> Antoine.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140822/9af5f5b7/attachment.html>
More information about the Python-ideas
mailing list