[Python-ideas] Optional static typing -- the crossroads
Bill Winslow
bunslow at gmail.com
Fri Aug 15 13:53:31 CEST 2014
Oh dear lord, it's like a nightmare where you're late to class without
clothing... except it actually happened... I knew something like this would
happen when I decided to actually do something.
On Fri, Aug 15, 2014 at 6:50 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 15 August 2014 21:01, Bill Winslow <bunslow at gmail.com> wrote:
> > Consider the following:
> >
> >
> >>>> from collections import abc as types
> >>>> isinstance(dict, types.Mapping)
> > False
> >>>> isinstance(types.Mapping, dict)
> > False
> >>>> isinstance(list, types.MutableSequence)
> > False
> >>>> isinstance(types.MutableSequence, list)
> > False
> >>>> isinstance(list, types.Sized)
> > False
>
> You're doing instance checks on subclasses - that's never going to
> work. Once you account for the type/instance distinction, you can see
> everything is correctly registered:
>
> >>> from collections import abc as cabc
> >>> issubclass(dict, cabc.Mapping)
> True
> >>> issubclass(list, cabc.Sequence)
> True
> >>> issubclass(list, cabc.Sized)
> True
> >>> isinstance(dict(), cabc.Mapping)
> True
> >>> isinstance(list(), cabc.Sequence)
> True
> >>> isinstance(list(), cabc.Sized)
> True
>
> (in Python 2, a couple of builtins claim ABCs they don't actually
> implement fully, but that's addressed in newer versions of Python 3)
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140815/386bb0d7/attachment.html>
More information about the Python-ideas
mailing list