Message131566
You misunderstood my last response. The first paragraph *dismisses* the case of temporary print (raised by Charles-Axle) as out of scope for doctests and hence this issue. The next ones addresses *your* case of code *permanently* intended to print and raise and gives a workable solution to your example.
After failing to find a simpler example that works with 3.x*, I am now thinking of the following doc fix.
1. Add 'directly' before 'supported' in Tim's first sentence: "Examples containing both expected output and an exception are not supported."
2. After the next sentence of explanation, add
"""Instead, try something like:
>>> def test():
... print("hello")
... raise IndexError()
...
>>> try:
... test()
... raise BaseException # Fail if no IndexError
... except IndexError:
... pass
hello
"""
* I discovered a subtle consequence of the print change: "print 1, 1/0" will print '1' on a line by itself and then a traceback. "print(1,1/0)" just prints a traceback. Something like
class C():
def __str__(self):
raise IndexError
print(1, C(), sep='\n')
is required to print a value by itself on a line and then a traceback.
That is no simpler and probably less realistic than test() above. |
|
Date |
User |
Action |
Args |
2011-03-20 23:22:02 | terry.reedy | set | recipients:
+ terry.reedy, tim.peters, georg.brandl, cjw296, charlax, docs@python |
2011-03-20 23:22:02 | terry.reedy | set | messageid: <1300663322.01.0.482248611546.issue3722@psf.upfronthosting.co.za> |
2011-03-20 23:22:01 | terry.reedy | link | issue3722 messages |
2011-03-20 23:22:01 | terry.reedy | create | |
|