Boolean tests [was Re: Attack a sacred Python Cow]
steve at REMOVE-THIS-cybersource.com.au
Thu Jul 31 05:29:28 CEST 2008
On Thu, 31 Jul 2008 02:41:08 +0000, Steven D'Aprano wrote:
> On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote:
>> Although, if my function is expecting a list, my preference is to do:
>> if not isinstance(x, list):
>> raise SomeMeaningfulException()
>> # do stuff with the list
>> I put my type checking at the top of the function, so readers can
>> reference it easily.
> And thus you break duck-typing and upset anybody who wants to pass a
> sequence that doesn't inherit directly from list.
Correction: delete "directly" from the above.
More information about the Python-list