Skip to content

[BUG] Unable to encrypt Chinese function #5873

@fggzs

Description

@fggzs

Describe the bug

Compiling 测试.py because it changed.
[1/1] Cythonizing 测试.py
D:\Python\Python311\Lib\site-packages\Cython\Compiler\Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: D:\MYpython\测试.py
  tree = Parsing.p_module(s, pxd, full_module_name)
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\Python\Python311\Scripts\easycython.exe\__main__.py", line 7, in <module>
  File "D:\Python\Python311\Lib\site-packages\begin\main.py", line 52, in start
    cmdline.apply_options(self.__wrapped__, opts,
  File "D:\Python\Python311\Lib\site-packages\begin\cmdline.py", line 253, in apply_options
    return_value = call_function(func, signature(ext), opts)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\Python311\Lib\site-packages\begin\cmdline.py", line 236, in call_function
    return func(*pargs, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\Python311\Lib\site-packages\easycython\easycython.py", line 77, in main
    ext_modules = cythonize(ext_modules),
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\Python311\Lib\site-packages\Cython\Build\Dependencies.py", line 1154, in cythonize
    cythonize_one(*args)
  File "D:\Python\Python311\Lib\site-packages\Cython\Build\Dependencies.py", line 1300, in cythonize_one
    result = compile_single(pyx_file, options, full_module_name=full_module_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\Python311\Lib\site-packages\Cython\Compiler\Main.py", line 615, in compile_single 
    return run_pipeline(source, options, full_module_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\Python311\Lib\site-packages\Cython\Compiler\Main.py", line 539, in run_pipeline   
    err, enddata = Pipeline.run_pipeline(pipeline, source)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\Python311\Lib\site-packages\Cython\Compiler\Pipeline.py", line 398, in run_pipeline
    data = run(phase, data)
           ^^^^^^^^^^^^^^^^
  File "D:\Python\Python311\Lib\site-packages\Cython\Compiler\Pipeline.py", line 375, in run        
    return phase(data)
           ^^^^^^^^^^^
  File "D:\Python\Python311\Lib\site-packages\Cython\Compiler\Pipeline.py", line 52, in generate_pyx_code_stage
    module_node.process_implementation(options, result)
  File "D:\Python\Python311\Lib\site-packages\Cython\Compiler\ModuleNode.py", line 222, in process_implementation
    self.generate_c_code(env, options, result)
  File "D:\Python\Python311\Lib\site-packages\Cython\Compiler\ModuleNode.py", line 550, in generate_c_code
    rootwriter.copyto(f)
  File "Cython\\Compiler\\Code.py", line 1846, in Cython.Compiler.Code.CCodeWriter.copyto
  File "Cython\\StringIOTree.py", line 81, in Cython.StringIOTree.StringIOTree.copyto
  File "Cython\\StringIOTree.py", line 81, in Cython.StringIOTree.StringIOTree.copyto
  File "Cython\\StringIOTree.py", line 84, in Cython.StringIOTree.StringIOTree.copyto
  File "<frozen codecs>", line 721, in write
  File "<frozen codecs>", line 377, in write
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 993-994: ordinal not in range(256)

Code to reproduce the behaviour:

def 测试():
    print("测试")
    
测试()

#Failed to build pyd on this simple Chinese function

Expected behaviour

No response

OS

windows

Python version

3.11.3

Cython version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions