Am 15.08.2013 01:10, schrieb Aaron Meurer:
>> Since timeouts are done by triggering a Skipped exception, I guess the right
>> way to handle this would be to turn GA_Printer into a context manager.
>> 1) What are the ramifications?
>
> There are none that I can think of. Probably on and off should be made
> private and the context managers made to be the only way to do things.
> Or maybe even just removed. The whole thing can just be
>
> from contextlib import contextmanager
>
> @contextmanager
> def GA_Printing():
> GA_Printer.Basic__str__ = Basic.__str__
> Basic.__str__ = lambda self: GA_Printer().doprint(self)
> yield
> Basic.__str__ = GA_Printer.Basic__str__
>
> (modulo any typos I made there of course)
>
> The only issue with removing them is that it gets to be more annoying
> to use it interactively (at least until the IPython devs come to their
> senses with
https://github.com/ipython/ipython/issues/3191).
I made a fix that keeps on() and off() as deprecated functions, and does
the actual work in new _on() and _off() functions.
The tests run fine with that :-)
I did that via __enter__ and __exit; the @contextmanager approach looks
cleaner, I'll integrate that and submit a pull request.
I'm wondering whether we should postpone deprecating on() and off()
until after #3191 is finished.
(I can see both side of the ongoing argument actually. I'd go for
enter_context and exit_context in Ipython, plus a diagnostic function to
list all active contexts. It's not ideal, but I don't think the ideal
thing is possible there.)
>> 2) Are there other things that need to be turned into a context manager?
>
> Probably a lot of stuff. Anything that sets something and then unsets
> it when it's done. It's hard to find by grepping.
Darn.
Something of that is probably already in the code that collects test
results for the final test summary. With timeout=1, I'm getting
mutilated or no output.
Somebody with more insight into the test runner code should comment on
that. I have no idea where to look first. (The test runner code could
use a good deal of refactoring and rewriting. It's a bit too much for
me, unfortunately.)
> Also, many try: finally blocks would be easier to read/use/reuse as
> context managers.
Worth doing.
I'll leave that to a GSoC student though :-)