New submission from Ismael Garrido <ismael...@gmail.com>: Using the "with" statement wrongly results in a confusing error message.
Code (originally written by Alex Gaynor): class Timer(object): def __enter__(self): self.start = time.time() def __exit__(self, exc_type, exc_val, tb): print "Section time: ", time.time() - self.start #Note the error here, I call the class, not an instance with Timer: pass ------------------------ Compare the Python 2.6 error: ismael@chaos:~/Escritorio$ python bad.py Traceback (most recent call last): File "bad.py", line 8, in <module> with Timer: TypeError: unbound method __enter__() must be called with Timer instance as first argument (got nothing instead) Against Python 2.7: ismael@chaos:~/Escritorio$ python2.7 bad.py Traceback (most recent call last): File "bad.py", line 8, in <module> with Timer: AttributeError: __exit__ ---------- components: Interpreter Core messages: 139918 nosy: Ismael.Garrido priority: normal severity: normal status: open title: "with" statement error message is more confusing in Py2.7 type: behavior versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue12503> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com