Bug? cgi.escape(int)

Alex Martelli aleax at aleax.it
Thu Jul 25 07:14:07 EDT 2002


Thomas Guettler wrote:
        ...
> Yes, I can do foo=str(foo) myself before calling escape,
> but this feature would hurt noone.

Many Python functions expect to get arguments of specific types
(or polymorphic to such types, i.e., supplying all necessary
methods and operations with equal signatures).

Having them accept arguments of wrong types, with silent coercion,
would hurt all careful developers, by hiding bugs.  Raising
exceptions when objects of wrong types are mistakenly passed
diagnoses such bugs earlier and enhances overall productivity.
As you notice, explicit coercion is trivially simple to ask for
explicitly, when that is what you want.

Explicit is better than implicit.  Python does not try to guess
at what you may have meant.  Errors should never pass silently,
unless explicitly silenced.  These guidelines WORK, when applied
with good taste and pragmaticity.  "Doing what I mean, for my
tiny momentary convenience and at the cost of hiding possible
errors" doesn't work -- specifically, it doesn't scale to serious
software development.  Python does scale.

When you can make a specific case for some relaxing of argument
type rules being specifically useful, please do -- that's what
PEPs (Python Enhancement Proposals) are for, among other things.
But in this case, I don't think you've made a good point (IMHO).


Alex



More information about the Python-list mailing list