Closed Kojoley closed 3 years ago
pure_eval doesn't deal with formatting so I can't imagine how it could affect this. stack_data would make more sense but I still don't know how. Can you provide a minimal script which reproduces the difference?
The IPython PR you linked seems to be about the 7.x branch which doesn't use stack_data, but maybe that's irrelevant.
it also shows a strange decision in locals order showing
I see one additional expression, not a change in order of existing expressions.
pure_eval doesn't deal with formatting so I can't imagine how it could affect this. stack_data would make more sense but I still don't know how. Can you provide a minimal script which reproduces the difference?
That might not be easy... I have just tried to reproduce it manually via typing things into IPython console and I see different indentation than via IPython testing suite.
Manually:
29 except IndexError:
30 mode = 'div'
---> 32 bar(mode)
mode = 'exit'
Via ipdoctests:
29 except IndexError:
30 mode = 'div'
---> 32 bar(mode)
mode = 'exit'
The IPython PR you linked seems to be about the 7.x branch which doesn't use stack_data, but maybe that's irrelevant.
That test is currently disabled in the main branch, and I was going to revive it (now I think I should not have been even bothered to :laughing:).
I see one additional expression, not a change in order of existing expressions.
I would expect the function arguments to be first and after that everything else, now local variables are in between of function arguments.
It sounds likely that this has something to do with IPython itself, maybe the data that it puts in linecache.
I would expect the function arguments to be first and after that everything else, now local variables are in between of function arguments.
The variables are being fetched in https://github.com/ipython/ipython/blob/master/IPython/core/ultratb.py#L677 which calls https://github.com/alexmojaki/stack_data/blob/1434eff144df5743e25f8e3b1db3ddfd30749cef/stack_data/core.py#L833 which as far as I can see orders variables by the lineno they first appear in but sets no order within each line.
Reproducer:
import builtins
import doctest
def get_ipython():
from IPython.terminal.interactiveshell import TerminalInteractiveShell
if TerminalInteractiveShell._instance:
return TerminalInteractiveShell.instance()
from IPython.testing import tools
config = tools.default_config()
config.TerminalInteractiveShell.simple_prompt = True
# Create and initialize our test-friendly IPython instance.
shell = TerminalInteractiveShell.instance(config=config)
return shell
builtins.get_ipython = get_ipython
builtins._ip = get_ipython()
builtins.ip = get_ipython()
builtins.ip.builtin_trap.activate()
text = """
In [19]: %run simpleerr.py exit 2
An exception has occurred, use %tb to see the full traceback.
SystemExit: (2, 'Mode = exit')
In [23]: %xmode verbose
Exception reporting mode: Verbose
In [24]: %tb
---------------------------------------------------------------------------
SystemExit Traceback (most recent call last)
<BLANKLINE>
... in <module>
29 except IndexError:
30 mode = 'div'
---> 32 bar(mode)
mode = 'exit'
<BLANKLINE>
... in bar(mode='exit')
20 except:
21 stat = 1
---> 22 sysexit(stat, mode)
mode = 'exit'
stat = 2
23 else:
24 raise ValueError('Unknown mode')
<BLANKLINE>
... in sysexit(stat=2, mode='exit')
10 def sysexit(stat, mode):
---> 11 raise SystemExit(stat, 'Mode = %s' % mode)
stat = 2
mode = 'exit'
<BLANKLINE>
SystemExit: (2, 'Mode = exit')
"""
filename = 'asd.py'
name = 'asd'
globs = {"__name__": "__main__"}
from IPython.testing.plugin.ipdoctest import IPDoctestOutputChecker, IPDocTestRunner, IPDocTestParser
optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
checker = IPDoctestOutputChecker()
runner = IPDocTestRunner(optionflags=optionflags,
checker=checker, verbose=False)
parser = IPDocTestParser()
test = parser.get_doctest(text, globs, name, filename, 0)
import os
import IPython.core.tests
os.chdir(os.path.dirname(IPython.core.tests.__file__))
failures = None
runner.run(test, out=failures, clear_globs=False)
It is fine when run after git checkout 73767d96a7140547f78c96d3c8d81352375afda6~1
and fails after git checkout 73767d96a7140547f78c96d3c8d81352375afda6
.
It sounds likely that this has something to do with IPython itself, maybe the data that it puts in linecache.
It could be IPython itself. I am fine with closing the issue if you think it is unlikely to be a pure_eval bug.
This script is definitely way too separated from pure_eval for me to work with. I don't want to figure out what's going on in IPython tests.
If you can reproduce using only stack_data (see the last code snippet in https://github.com/alexmojaki/stack_data) I'll take a look.
I notice your test data doesn't show the value of 'Mode = %s' % mode
. I assume that alone causes a failure in the newer commit which added support for binary operations like that. See if you can reproduce the problem when no binary operations are involved, i.e. the only difference is indentation, not variables. Maybe somehow adding a 'variable' affected the indentation?
I think the indentation difference came with switching to stack_data in https://github.com/ipython/ipython/pull/11886 and I was just fooled by test failure diff that shows indentation difference even when it would be ignored later. Sorry for bothering you.
Since
pure_eval>=0.2.0
stack traces thatstack_data
generates had changed in indentation, was that intentional? (IPython
tests were affected by that https://github.com/ipython/ipython/pull/12874)In 0.1.1:
Since 0.2.0:
Full diff https://gist.github.com/Kojoley/fe2f74026457e84e65818201c9c6ce15/revisions (it also shows a strange decision in locals order showing)
Previously original code indentation was shown in the backtrace and now it is deindented by 1 step.
I have bisected the change to 73767d96a7140547f78c96d3c8d81352375afda6 commit.