atom / language-python

Python package for Atom
Other
190 stars 146 forks source link

Atom Hydrogen error "unexpected EOF while parsing" for python `if` statement!? (but not other statements) #299

Closed bridgesra closed 5 years ago

bridgesra commented 5 years ago

Prerequisites [X ] Put an X between the brackets on this line if you have done all of the following: Reproduced the problem in Safe Mode: https://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode Note--hydrogen doesn't seem to work in safe mode, so couldn't fully check, but the if statements won't fold indicating it's still a problem.

Followed all applicable steps in the debugging guide: https://flight-manual.atom.io/hacking-atom/sections/debugging/

Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq

Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom

Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages

Steps to Reproduce type any if statement in a saved Python script put cursor on the if line execute w/ Hydrogen (Shift + Enter) Expected behavior: Should run the whole if statement

Actual behavior: [What actually happens] If there is no else in the if statement it produces "Unexpected EOF while parsing " error . If there is an else in the if statement if runs the first if portion of the statement but not the elif or else part(s).

Reproduces how often: 100%

Versions Editor name and version: Atom 1.35.1 apm 2.1.3 npm 6.2.0 node 8.9.3 x64 atom 1.35.1 python 2.7.15 git 2.14.3

Platform: Mac OS Sierra 10.12.6

Color scheme: One Dark/Solarized Dark

Additional Information Seems to be a problem w/ how Atom / Hydrogen interprets the code. for loops it will give me the option to "fold" or "collapse" by clicking the carrot in the line number. Yet, if blocks/statements have no such luck.

this works:

for i in range(10): print( i)

this doesn't:

if not False: print("test worked")

this example doesn't throw an error, but only executes the "if" and not the else parts:

x= False if x == True: print("test") elif x == None: print ('test anyway') else: print('test again')

seems related to this: https://discuss.atom.io/t/python-cant-fold-just-a-elif/60490/2

picture of errors w/ `if`:

bridgesra commented 5 years ago

correction of code syntax from above:

## this works:
for i in range(10):
    print( i)

##this doesn't:
if not False:
    print("test worked")

## this example doesn't throw an error, but only executes the "if" and not the else parts:
x= False
if x == True:
    print("test")
elif x == None:
    print ('test anyway')
else:
    print('test again')
Arcanemagus commented 5 years ago

Thanks for contributing!

As you were already told over in https://github.com/atom/atom/issues/19132, this is being caused by the hydrogen package, not Atom itself. Atom has nothing to do with executing code, that is entirely handled by external packages.

It may be that there is still a bug in Atom. If so, we'll need the maintainer of the package that is causing the problem to help track that down. You should file this issue on their repository so they can either fix the problem or tell us where the problem is coming from. The Atom FAQ has information on how to contact the maintainers of any Atom community package or theme.

bridgesra commented 5 years ago

@Arcanemagus Thank you. As you can see from the post, folding of if statements in python is still an issue w/ language-python v. 0.51.9. While it seems the last few commits tried to fix, I believe that this still may be a relevant bug for language-python. I can't say if the incorrect folding (fact that it doesn't recognize whole if statements in python) is causing the hydrogen execution errors, but it certainly seems like the same problem. Note that if i highlight the whole if statement and execute with hydrogen it works properly. If the cursor is on the first line of the if statement if does not. Folding still is incorrect for python if.

Arcanemagus commented 5 years ago

Your example text looks like this in the v1.38.0-nightly1 build of Atom: image

And appears to fold correctly for me: image

We just released a new version of Atom, however the language-python update only made it into the beta of the next release. You can try that version out to see if it resolves your issue. If the above folding doesn't look correct to you please open a new issue outlining what you see as wrong with it, remembering that Hydrogen or executing the code has nothing to do with Atom and should be discussed with them.

Ben3eeE commented 5 years ago

@bridgesra I noticed an issue with folding lone if statements earlier today and opened https://github.com/atom/language-python/pull/300 to fix it.

bridgesra commented 5 years ago

@Arcanemagus Thanks. I will cross post the execution error w/ Hydrogen too. I was unsure about whether to do that. RE: the if/elif/else folding. I'm not sure if that's "correct" or if the whole 3-part if statement should fold--both seem reasonable foldings to me.

@Ben3eeE Correct, single if statements are not presenting a carrot or folding at all in my experience. Thanks for being more clear.