[Python-3000] Builtin iterator type

George Sakkis gsakkis at rutgers.edu
Wed Nov 15 19:47:50 CET 2006


On 11/15/06, Josiah Carlson <jcarlson at uci.edu> wrote:
>
> "George Sakkis" <gsakkis at rutgers.edu> wrote:
> > As I wrote in my last reply to Nick though, I question Python's right to perform
> > such limited forms of design-by-contract-like assertions ("why not add
> > a precondition
> > on __add__(self,other) to enforce isinstance(other, self.__class__)
> > ?") when it refuses to formalize interfaces for sequences, iterators
> > et al.
>
> Because 5, 5+0j, 5.0 are different types.  To not be able to add any of
> them because they are different types, would be silly.  Note that
> Decimal is a different beast, which is why I don't include it.  There's
> also string + unicode (at least in 2.x), and if some sort of
> unicode view makes it into 3.x, view + unicode.

You missed my point; I wasn't seriously suggesting that there should
be more checks (hence the quotes), but rather the contrary, that
checking whether len() returns a non-negative integer does very little
to the overall consistency scheme of things.

Pre-conditions, post-conditions, invariants are a stricter form of API
conformance than just checking whether a method with a specific name
is there, and Python is unwilling to check even that.

George


More information about the Python-3000 mailing list