GNU bug report logs -
#39070
python interpreter within Emacs fails on simple test (syntax error)
Previous Next
Reported by: Pierre ALBARÈDE <pa.com <at> free.fr>
Date: Fri, 10 Jan 2020 15:34:01 UTC
Severity: normal
Tags: notabug
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 39070 in the body.
You can then email your comments to 39070 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#39070
; Package
emacs
.
(Fri, 10 Jan 2020 15:34:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Pierre ALBARÈDE <pa.com <at> free.fr>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Fri, 10 Jan 2020 15:34:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
This small program
mac2011% cat bug.py
print(__name__ == "__main__")
#if True:
if __name__ == "__main__":
print("main")
else:
print("not main")
works well in Terminal :
mac2011% python bug.py
True
main
mac2011% python --version
Python 3.6.9 :: Anaconda, Inc.
but it does not work in Emacs python mode :
mac2011% Emacs -Q bug.py
(version)
"GNU Emacs 28.0.50 (build 1, x86_64-apple-darwin15.6.0, NS appkit-1404.47
Version 10.11.6 (Build 15G22010))
of 2020-01-09"
Files opens in (Python ElDoc) mode
Python menu
Start interpreter (C-c C-p)
Eval buffer (C-c C-c)
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 13:42:17)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python.el: native completion setup loaded
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/alba/Documents/projets/plot time series/bug.py", line 5
else:
^
SyntaxError: invalid syntax
>>>
Replacing 'if __name__ == "__main__":' by 'if True:', there is no more error.
Replacing "__main__" by "__main_", there is no more error.
Same with Python 3.7.6.
'print("main") if __name__ == '__main__' else print("not main")' works.
Best regards.
--
Pierre ALBARÈDE
[smime.p7s (application/pkcs7-signature, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#39070
; Package
emacs
.
(Tue, 04 Feb 2020 00:04:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 39070 <at> debbugs.gnu.org (full text, mbox):
> Replacing 'if __name__ == "__main__":' by 'if True:', there is no more error.
>
> Replacing "__main__" by "__main_", there is no more error.
>
> Same with Python 3.7.6.
>
> 'print("main") if __name__ == '__main__' else print("not main")' works.
>
> Best regards.
Hello Pierre,
This behavior is due to `python-shell-send-buffer's SEND-MAIN
argument:
"When optional argument SEND-MAIN is non-nil, allow execution of
code inside blocks delimited by "if __name__== '__main__'" "
So when this argument is nil (the default), the whole block under "if
__name__== '__main__'" " will be removed (along the line containing the
"if" itself).
Your example breaks because you added an "else:" to your "if", so when
Emacs removes that part, a syntax error is raised.
Try the following test file:
print("1")
if __name__ == "__main__":
print("2")
print("3")
Using C-c C-c on it should yield "1 3", but using C-u C-c C-c
(i.e. SEND-MAIN set to t) should yield "1 2 3".
Hope that helps.
- Fede
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#39070
; Package
emacs
.
(Sat, 30 Jan 2021 06:54:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 39070 <at> debbugs.gnu.org (full text, mbox):
Federico Tedin <federicotedin <at> gmail.com> writes:
> Using C-c C-c on it should yield "1 3", but using C-u C-c C-c
> (i.e. SEND-MAIN set to t) should yield "1 2 3".
So I guess this works as designed, and I'm closing this bug report.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) notabug.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Sat, 30 Jan 2021 06:54:02 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
39070 <at> debbugs.gnu.org and Pierre ALBARÈDE <pa.com <at> free.fr>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Sat, 30 Jan 2021 06:54:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 27 Feb 2021 12:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 30 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.