diff --git a/IPython/core/magics/code.py b/IPython/core/magics/code.py index b2ab688..6d1fce5 100644 --- a/IPython/core/magics/code.py +++ b/IPython/core/magics/code.py @@ -98,11 +98,12 @@ def extract_symbols(code, symbols): >>> extract_symbols(code, 'A,b,z') (["class A: pass", "def b(): return 42"], ['z']) """ + symbols = symbols.split(',') try: py_code = ast.parse(code) except SyntaxError: # ignores non python code - return [] + return [], symbols marks = [(getattr(s, 'name', None), s.lineno) for s in py_code.body] code = code.split('\n') @@ -126,7 +127,7 @@ def extract_symbols(code, symbols): # fill a list with chunks of codes for each requested symbol blocks = [] not_found = [] - for symbol in symbols.split(','): + for symbol in symbols: if symbol in symbols_lines: start, end = symbols_lines[symbol] blocks.append('\n'.join(code[start:end]) + '\n') diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index cb457e9..fbf34a5 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -79,7 +79,7 @@ def test_extract_symbols_ignores_non_python_code(): "def hello\n" "puts 'Hello world'\n" "end") - nt.assert_equal(code.extract_symbols(source, "hello"), []) + nt.assert_equal(code.extract_symbols(source, "hello"), ([], ['hello'])) def test_rehashx():