Returning different types based on input parameters

andrew cooke andrew at
Tue Apr 7 01:53:01 CEST 2009

George Sakkis wrote:
> That's more of a general API design question but I'd like to get an
> idea if and how things are different in Python context. AFAIK it's
> generally considered bad form (or worse) for functions/methods to
> return values of different "type" depending on the number, type and/or
> values of the passed parameters. I'm using "type" loosely in a duck-
> typing sense, not necessarily as a concrete class and its descendants,
> although I'm not sure if even duck-typing is endorsed for return
> values (as opposed to input parameters).

you probably want to look up substitutability:


More information about the Python-list mailing list