Returning different types based on input parameters
andrew cooke
andrew at acooke.org
Mon Apr 6 19:53:01 EDT 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:
http://www.google.cl/search?q=substitutability+principle
andrew
More information about the Python-list
mailing list