Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture restores stdout even if function func() fails #1168

Merged
merged 1 commit into from Mar 25, 2012

Conversation

smichr
Copy link
Member

@smichr smichr commented Mar 25, 2012

Previously, if you made a mistake in the function you passed
    to capture, it would not restore the output to stdout.

    e.g.

>>> capture(pprint(x/y))
x
-
y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    File "sympy\utilities\iterables.py", line 461, in capture
        func()
    TypeError: 'NoneType' object is not callable
>>> print 1 # output still captured by StringIO
>>>

>>> def foo():
... print 'hello world!'
...
>>> 'hello' in capture(foo) # foo, not foo()
True
>>> capture(lambda: pprint(2/x))
'2\n-\nx\n'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand, but test report point out about those lines.

ValueError: line 16 of the docstring for sympy.utilities.iterables.capture has inconsistent leading whitespace: '-'

    Previously, if you made a mistake in the function you passed
    to capture, it would not restore the output to stdout.

    e.g.

>>> capture(pprint(x/y))
x
-
y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    File "sympy\utilities\iterables.py", line 461, in capture
        func()
	TypeError: 'NoneType' object is not callable
>>> print 1 # output still captured by StringIO
>>>
@smichr
Copy link
Member Author

smichr commented Mar 25, 2012

the doctest has been fixed by escaping the \n

@smichr
Copy link
Member Author

smichr commented Mar 25, 2012

@goodok , are you ok with this now?

@goodok
Copy link
Contributor

goodok commented Mar 25, 2012

Yes, I can merge it.

It solve the problems with sys.stdout restoring.

goodok added a commit that referenced this pull request Mar 25, 2012
capture restores stdout even if function func() fails
@goodok goodok merged commit 3400a17 into sympy:master Mar 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants