[Python-Dev] Exception message for invalid with statement usage
Guido van Rossum
guido at python.org
Wed Sep 6 17:46:21 CEST 2006
IMO it's fine. The only time you'll see this in reality is when
someone passed you the wrong type of object by mistake, and then the
type mentioned in the message is plenty help to debug it. Anyone with
even a slight understanding of 'with' knows it involves '__exit__',
and the linenumber should be a big fat hint, too.
On 9/6/06, Georg Brandl <g.brandl at gmx.net> wrote:
> Current trunk:
>
> >>> with 1:
> ... print "1"
> ...
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'int' object has no attribute '__exit__'
>
> Isn't that a bit crude? For "for i in 1" there's a better
> error message, so why shouldn't the above give a
> TypeError: 'int' object is not a context manager
>
> ?
>
> Georg
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list