(A) This works:
def func():
x = 1
print(x)
return
(B) This doesn't work:
def func():
x = 1
print(x)
return
(C) This also doesn't work: (Here I am using '_' to indicate a white space)
def func():
x = 1
____
print(x)
return
(D) This works:
def func():
x = 1
____# some comment
print(x)
return
In both (B) and (C) I get the following errors:
- NameError: name 'x' is not defined
- SyntaxError: 'return' outside function
I am using Eclipse and the PyDev plug-in. The Python version is 3.5 and the PyDev version is 4.5.
----------update----------
The issue is not reproducible in Jupyter Notebook and PyCharm.
In Eclipse I have turned on "Show whitespace characters". The indent in (C) is indeed composed of 4 whitespaces which are displayed as 4 dots in the editor. If it was a tab, in the Eclipse editor it would be displayed as ">> ".
Given my through investigation and the comments/answers below, I am pretty sure this is a stupid bug of Eclipse and/or PyDev.
Thank you all for helping.