rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 254 forks source link

%lprun throws exception when single quoted strings are used in the statement in IPython #124

Open hodossy opened 6 years ago

hodossy commented 6 years ago

Code to reproduce the issue

%load_ext line_profiler

def hello(name):
    greeting = 'Hello {}!'.format(name)
    print(greeting)

%lprun -f hello hello("World") # This one is working fine
%lprun -f hello hello('World') # Throws exception

Output:

Hello World!

Traceback (most recent call last):

  File "c:\workspace\.env\lib\site-packages\IPython\core\interactiveshell.py", line 2963, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-17-a9a8fe65d042>", line 8, in <module>
    get_ipython().run_line_magic('lprun', "-f hello hello('World')")

  File "c:\workspace\.env\lib\site-packages\IPython\core\interactiveshell.py", line 2131, in run_line_magic
    result = fn(*args,**kwargs)

  File "<decorator-gen-127>", line 2, in lprun

  File "c:\workspace\.env\lib\site-packages\IPython\core\magic.py", line 187, in <lambda>
    call = lambda f, *a, **k: f(*a, **k)

  File "c:\workspace\.env\lib\site-packages\line_profiler.py", line 356, in lprun
    profile.runctx(arg_str, global_ns, local_ns)

  File "c:\workspace\.env\lib\site-packages\line_profiler.py", line 151, in runctx
    exec_(cmd, globals, locals)

  File "<string>", line 1
    hello(\'World\')
                    ^
SyntaxError: unexpected character after line continuation character

Versions:

Python 3.6.3 on 64bit Windows: ipykernel==4.8.0 ipython==6.2.1 ipython-genutils==0.2.0 ipywidgets==7.1.1 jupyter==1.0.0 jupyter-client==5.2.2 jupyter-console==5.2.0 jupyter-core==4.4.0 notebook==5.4.0 line-profiler==2.1.2

jamilraichouni commented 4 years ago

Confirmed!

shenker commented 4 years ago

Likewise.