[Python-ideas] An ABC representing "Iterable, Sized, Container"

Guido van Rossum guido at python.org
Mon Jul 25 13:58:04 EDT 2016

On Mon, Jul 25, 2016 at 10:19 AM, Gregory P. Smith <greg at krypto.org> wrote:
> Given how often the str problem comes up in this context, I'm thinking a
> common special case in type annotation checkers that explicitly exclude str
> from consideration for iteration.  It's behavior is rarely what the
> programmer intended and more likely to be a bug.

Should we have IterableButNotString, CollectionExceptString,
NonStringSequence, or all three? I suppose the runtime check would be
e.g. isinstance(x, Iterable) and not isinstance(x, (str, bytes,
bytearray, memoryview))? And the type checker should special-case the
snot out of it?

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list