[Python-apps-team] Bug#500847: [cython] Does not accept Unicode docstrings

P M pagx13 at yahoo.gr
Wed Oct 1 23:28:13 UTC 2008

Package: cython
Version: 0.9.8-1
Severity: normal

Cython does not accept Unicode docstrings in .pyx files. I have attached a 
sample session with a .pyx file, where I define a function with a docstring 
containing Greek characters. The file's contents are in UTF-8. What is more, 
instead of an error message, I got a python traceback! This problem does not 
show up with comments in Unicode or other string literals.

$ cat bug.pyx
def hello():
        '''Γειά σου, κόσμε!'''
        print 'Hello, world!'
$ cython bug.pyx
Traceback (most recent call last):
  File "/usr/bin/cython", line 8, in <module>
    main(command_line = 1)
  File "/var/lib/python-support/python2.5/Cython/Compiler/Main.py", line 527, 
in main
    result = compile(sources, options)
  File "/var/lib/python-support/python2.5/Cython/Compiler/Main.py", line 505, 
in compile
    return compile_multiple(source, options)
  File "/var/lib/python-support/python2.5/Cython/Compiler/Main.py", line 472, 
in compile_multiple
    result = context.compile(source, options)
  File "/var/lib/python-support/python2.5/Cython/Compiler/Main.py", line 327, 
in compile
    tree.process_implementation(scope, options, result)
  File "/var/lib/python-support/python2.5/Cython/Compiler/ModuleNode.py", line 
59, in process_implementation
    self.generate_c_code(env, options, result)
  File "/var/lib/python-support/python2.5/Cython/Compiler/ModuleNode.py", line 
243, in generate_c_code
    self.body.generate_function_definitions(env, code, options.transforms)
  File "/var/lib/python-support/python2.5/Cython/Compiler/Nodes.py", line 839, 
in generate_function_definitions
    with_pymethdef = env.is_py_class_scope)
  File "/var/lib/python-support/python2.5/Cython/Compiler/Nodes.py", line 
1442, in generate_function_header
  File "/var/lib/python-support/python2.5/Cython/Compiler/Code.py", line 52, 
in putln
  File "/var/lib/python-support/python2.5/Cython/Compiler/Code.py", line 69, 
in put
UnicodeEncodeError: 'ascii' codec can't encode characters in position 38-41: 
ordinal not in range(128)

Thank you for your time.

--- System information. ---
Architecture: amd64
Kernel:       Linux 2.6.26-1-amd64

Debian Release: lenny/sid
  990 testing         security.debian.org 
  990 testing         ftp.duth.gr 
  990 testing         ftp.de.debian.org 
  500 unstable        ftp.duth.gr 
  500 unstable        ftp.de.debian.org 
  500 stable          www.dipconsultants.com 
  500 lenny           kde4.debian.net 
    1 experimental    ftp.de.debian.org 

--- Package information. ---
Depends             (Version) | Installed
python                        | 2.5.2-2
python-support     (>= 0.7.1) | 0.8.4

More information about the Python-apps-team mailing list