[pypy-issue] [issue781] Confusing error message on "with"
Ismael
tracker at bugs.pypy.org
Wed Jul 6 05:46:33 CEST 2011
New submission from Ismael <ismaelgfk at 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 CPython 2.6 error:
ismael at chaos:~/Escritorio$ python slow.py
Traceback (most recent call last):
File "slow.py", line 31, in <module>
with Timer:
TypeError: unbound method __enter__() must be called with Timer instance as
first argument (got nothing instead)
Against PyPy 1.5:
ismael at chaos:~/Escritorio$ ~/pypy/bin/pypy slow.py
Traceback (most recent call last):
File "app_main.py", line 53, in run_toplevel
File "slow.py", line 31, in <module>
with Timer:
AttributeError: __exit__
----------
messages: 2738
nosy: Ismael, pypy-issue
priority: wish
release: 1.5
status: unread
title: Confusing error message on "with"
________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue781>
________________________________________
More information about the pypy-issue
mailing list