Python is DOOMED! Again!

Chris Angelico rosuav at
Thu Jan 22 16:13:25 CET 2015

On Fri, Jan 23, 2015 at 1:57 AM, Steven D'Aprano
<steve+comp.lang.python at> wrote:
> Chris Angelico wrote:
>> Hold on a moment, how often do you really do this kind of thing with
>> "might be one of them or a sequence"?
> isinstance(obj, one_class_or_tuple_of_classes)
> issubclass(cls, one_class_or_tuple_of_classes)
> mystr.startswith(prefix_or_tuple_of_prefixes)
> mystr.endswith(suffix_or_tuple_of_suffixes)
> template % one_string_or_tuple_of_strings  # or a dict :-)
> I'm not suggesting that the specific example is a good one, but the
> principle is sound.

All of your examples are "might be one of them or a tuple". Not
"sequence", "tuple". That gets around the problem of recognition,
because in no case is a single tuple a valid argument.

I suspect it would be possible to use TypeVar to create a nice
"OneOrMore" like you suggested, but for reliability, it should
probably be "or tuple" rather than "or sequence".


More information about the Python-list mailing list