Boolean tests [was Re: Attack a sacred Python Cow]
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Wed Jul 30 23:29:28 EDT 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.
--
Steven
More information about the Python-list
mailing list