[Python-ideas] Allow isinstance second argument to be a set of types

Chris Rebert pyideas at rebertia.com
Tue Jul 5 00:18:03 CEST 2011


On Mon, Jul 4, 2011 at 2:55 PM, Amaury Forgeot d'Arc <amauryfa at gmail.com> wrote:
> 2011/7/4 Michael Foord <fuzzyman at gmail.com>:
>>> > Arbitrary iterables, arbitrarily nested...
>>> > beware of objects which are also their first element, like str('a')...
>>>
>>> Ouch. I guess that shoots the proposal dead in the water, then.
>>
>> Why? Iteration doesn't imply recursing into contained iterators.
>
> isinstance already accept nested tuples:
>
> assert isinstance(1, (str, (int, float)))

That doesn't mean it has to necessarily accept other nested
containers; tuples can be left as a special case for backward
compatibility.
Why does it accept nested tuples in the first place for that matter?

Cheers,
Chris



More information about the Python-ideas mailing list