Skip to content

Commit b65cf89

Browse files
authored
validate ESC_PAREN ('/') is followed by a callable name and not empty (ipython#12690)
When running a single python expression with just a slash - `/`, a tuple is returned. ```python In [1]: / Out[1]: () ``` This weird case happens because when a line starts with `/` the `inputtransformer` transforms it into a call of the first word after the `/` as the callable name and rest tokens after as arguments. This PR fixes that issue by validating that at least a callable name is given and it's not empty, if not a `SyntaxError` will be raised. ```python In [1]: / File "<ipython-input-1-8f27084b6294>", line 1 / ^ SyntaxError: invalid syntax In [2]: ``` Validated that tests are passing.
2 parents 6aa7cdc + e8c9870 commit b65cf89

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

IPython/core/inputtransformer2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ def _tr_quote2(content):
395395

396396
def _tr_paren(content):
397397
"Translate lines escaped with a slash: /"
398-
name, _, args = content.partition(' ')
398+
name, _, args = content.partition(" ")
399+
if name == "":
400+
raise SyntaxError(f'"{ESC_SHELL}" must be followed by a callable name')
401+
399402
return '%s(%s)' % (name, ", ".join(args.split()))
400403

401404
tr = { ESC_SHELL : 'get_ipython().system({!r})'.format,

0 commit comments

Comments
 (0)