I have a simple test file, test01.py, with this output: $ cat test01.py #!/usr/bin/env python print("Line 1") print("Line 2") print("Line 3") $ $ # Now try debugging it. $ python3.0 -mpdb test01.py --Return-- > /home/ericp/opt/Python-3.0.1/lib/python3.0/io.py(762)closed()->False -> return self.raw.closed (Pdb) b test01.py:4 Breakpoint 1 at /home/ericp/lab/Python-3.0.1/test01.py:5 (Pdb) r --Return-- > /home/ericp/opt/Python-3.0.1/lib/python3.0/io.py(1471)closed()->False -> return self.buffer.closed (Pdb) c line 1 line 2 line 3 The program finished and will be restarted Two main problems: 1. I shouldn't see the code for io.py 2. The program doesn't stop at the breakpoint, because that stack frame is exposed to bdb as (file:"", line:4), not (file:"/home/.../test01.py", line:4).
Similar problem with 3.1rc1: C:\...>c:\Python31rc1\python.exe -m pdb hello01.py --Return-- > c:\python31rc1\lib\encodings\cp437.py(19)encode()->b'Hello' -> return codecs.charmap_encode(input,self.errors,encoding_map)[0] (Pdb) b 2 *** Blank or comment (Pdb) b hello01.py:2 Breakpoint 1 at c:\...\hello01.py:2 (Pdb) b Num Type Disp Enb Where 1 breakpoint keep yes at c:\...\hello01.py:2 (Pdb) c Hello here bye The program finished and will be restarted --Return-- > c:\python31rc1\lib\encodings\cp437.py(19)encode()->b'Hello' -> return codecs.charmap_encode(input,self.errors,encoding_map)[0] (Pdb)
Reading this patch, is it normal that the file is opened in text mode without an encoding specified? What if the source file uses a different encoding than the default system one?
That's a good question :) A quick test shows that exec() does honor coding cookies in code given as a bytestring, so simply changing to open(..., "rb") should be fine.