SyntaxError on py-execute-region

Bug #691542 reported by Yuri Goncharov
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Undecided
Andreas Roehler

Bug Description

I got error:
SyntaxError: Non-ASCII character '\xd0' in file /temp/python-abcd.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

There are patch:
diff -u orig/python-mode.el mod/python-mode.el
--- orig/python-mode.el 2009-01-29 22:34:59.000000000 +0300
+++ mod/python-mode.el 2010-12-17 16:15:54.088455001 +0300
@@ -1731,6 +1731,7 @@
       (let ((needs-if (/= (py-point 'bol) (py-point 'boi))))
         (set-buffer buf)
         (python-mode)
+ (insert "#-*- coding: utf-8 -*-\n")
         (when needs-if
           (insert "if 1:\n")
           (setq py-line-number-offset (- py-line-number-offset 1)))

Related branches

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi Yuri,

don't think it's a python-mode bug.

As you're pointing to the pep, it's seems good to have the encoding declared.

BTW here my python-files always start with

#! /usr/bin/env python
# -*- coding: utf-8 -*-

However, providing this seems not the task of python-mode, it's at the user to decide.

Andreas

Revision history for this message
Maik Beckmann (beckmann-maik) wrote :

Andreas,

I can confirm the bug Yuri reported and it doesn't help to have # -*- coding: utf-8 -*- at the top of a file, since it isn't considered by py-execute-region if it's not included in the selection. which defies the purpose of evaluating a region.

An example. Give this file
{{{
# -*- coding: utf-8 -*-
print "ö"
}}}
Using py-execute-buffer works fine, since it send
  # -*- coding: utf-8 -*-
to the interpreter.
Now select `print "ö"' and use py-execute-region. It will trigger the error mention by Yuri, since it doesn't send the encoding information to the interpreter.

Best,
Maik

Changed in python-mode:
status: New → Confirmed
Changed in python-mode:
status: Confirmed → In Progress
Changed in python-mode:
status: In Progress → Fix Committed
Revision history for this message
Andreas Roehler (a-roehler) wrote : dropping py-emacs-features

Hi,

while hunting bug #691542 --SyntaxError on py-execute-region--

consider to drop const `py-execute-region'.

Assume, if used at all, things should rather be fixed at the source than
dealt with here.

Should somebody use it, please send a note.

Thanks

Andreas

--
https://code.launchpad.net/~a-roehler/python-mode/python-mode-components
https://code.launchpad.net/s-x-emacs-werkstatt/

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Python-mode] dropping py-emacs-features

Am 18.04.2011 11:32, schrieb Andreas Röhler:
> Hi,
>
> while hunting bug #691542 --SyntaxError on py-execute-region--
>
> consider to drop const `py-execute-region'.

Typo: py-emacs-features

is at stake

>
> Assume, if used at all, things should rather be fixed at the source than
> dealt with here.
>
> Should somebody use it, please send a note.
>
> Thanks
>
>
> Andreas
>
> --
> https://code.launchpad.net/~a-roehler/python-mode/python-mode-components
> https://code.launchpad.net/s-x-emacs-werkstatt/
>
> _______________________________________________
> Python-mode mailing list
> <email address hidden>
> http://mail.python.org/mailman/listinfo/python-mode
>

Revision history for this message
Barry Warsaw (barry) wrote :

Agreed. py-emacs-features seems useless.

Changed in python-mode:
milestone: none → 6.0
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.