Bug? cgi.escape(int)

Thomas Guettler zopestoller at thomas-guettler.de
Thu Jul 25 09:26:44 EDT 2002


Alex Martelli wrote:

> 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. 


I agree, but than the exception should have a better message:

$ python escape.py
Traceback (most recent call last):
   File "escape.py", line 3, in ?
     cgi.escape(2)
   File "/usr/lib/python2.2/cgi.py", line 1024, in escape
     s = s.replace("&", "&") # Must be done first!
AttributeError: 'int' object has no attribute 'replace'


A exception with a message like:
"Argument must be a string"

would be better

  thomas




More information about the Python-list mailing list