Boolean tests [was Re: Attack a sacred Python Cow]

Carl Banks pavlovevidence at gmail.com
Fri Aug 1 17:13:04 EDT 2008


On Aug 1, 4:45 pm, Carl Banks <pavlovevide... at gmail.com> wrote:
> On Aug 1, 3:36 pm, Terry Reedy <tjre... at udel.edu> wrote:
> > In general, asking code to apply across numeric, container, and other
> > classes is asking too much.  Python code can be generic only within
> > protocol/interface categories such as number-like, sortable, and
> > iterable.  But making tests too specific can unnecessarily prevent even
> > that.
>
> At some point we have to throw our hands up and realize that if we're
> working with custom classes with varying degrees of nonconformance,
> there is nothing we can do that's safe.

And I want to make clear I'm not trying to downplay your example
here.  The example you gave me definitely fits the criteria of being a
useful "if x" that can't be replaced by a simple explicit test, at
least after my alteration to a vector example.

It's a concern when you write code that breaks realistic custom
classes, but really concerning when it breaks built-in classes.


Carl Banks



More information about the Python-list mailing list