-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Ellipsis as dictionary literal key causes Syntax Error #11269
Comments
I believe I see where this is coming from. @takluyver did work on the tokinsation, so may have some more insight, and does have plan to refactor. Thanks for the exaustive use case, that would be of great help when we work on this. |
I suspect it's hard to avoid that totally given what we want to do. We could decide to stop doing that; it would in some senses be more 'correct' not to, because it can mangle valid Python code, as you found. On the other hand, that's still what the prompts in the Python shell look like, I still see examples including the prompts, and there are an unknown number of people using this feature to copy-paste examples without having to remove all the prompts manually. So maybe we just have to write this off as a corner case. |
I agree it's an unimportant corner case, most people don't even know Also, didn't know I could paste code with prompt 😮 definitely more valuable |
Stumbled on this again today, even in strings that looks like console input are stripped: Because of my previous problem, I learned why, ipython applies the That is, just remove it by running from IPython.core.inputtransformer2 import PromptStripper
fs = get_ipython().input_transformers_cleanup
fs.remove(next(f for f in fs if isinstance(f, PromptStripper))) The elipsis case of my previous problem will work also |
btw @takluyver now I think It's possible to keep the 'raw console paste' functionality and fix these cases, at least if there is a preprocess step done 'by cell' instead of 'by line' (which I guess there is right? How does autoawait work? Wraps each line in functions?). Just made a cell magic as POC, that simply uses edit Just noticed it actually works by cell already, so the POC is: import ast
from IPython.core.inputtransformer2 import PromptStripper
prev = PromptStripper.__call__
def wrapper(self, lines):
try:
ast.parse(''.join(lines))
return lines
except SyntaxError:
return prev(self, lines)
PromptStripper.__call__ = wrapper |
Probably too specific to receive attention but maybe it highlights some internal design flaw or something:
Both in IPython console and Jupyter notebook cells (with ipython kernel), the following happens:
set({42})
returned)And all these cases works fine in a source file ot in normal python repl (tested 3.5, 3.6, 3.7 and IPython 6.5.0)
I realize it's a very specific bug with an easy workaround, and it's probably similar to #2605 and #4059 , but I was working in jupyter using a
match(obj, cases)
function (eg:match(foo(), {'bar' : 42})
, using...
for the default case and this bug tripped me so hard before I started to understand, it was worthy of this issueThe text was updated successfully, but these errors were encountered: