Skip to content

[BUG] cython -2 optimizes repeated strings "b'inappropriately'" #3951

Closed
@Alphadelta14

Description

@Alphadelta14

Describe the bug
When building against Python 2 (I know, we are running into this because we migrated all of our build tools to Python 3) using Cython in Python 3 (cython -2), some string optimizations like "-"*5 get expanded to "b'-----'" instead of the expected "-----".

To Reproduce
Files to reproduce:

expand.py

from __future__ import print_function
print("-"*5)
pip2 install Cython
cython -2 expand.py -o expand_cy2_3.0a6_2_good.c
gcc -shared -fPIC "-I$(python2 -c "import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'))")" -o expand.so expand_cy2_3.0a6_2_good.c
python2 -c "import expand"
# Out: -----

pip3 install Cython
cython -2 expand.py -o expand_cy3_3.0a6_2_bad.c

gcc -shared -fPIC "-I$(python2 -c "import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'))")" -o expand.so 
 expand_cy3_3.0a6_2_bad.c
python2 -c "import expand"
# Out: b'-----'

Expected behavior
As outlined above, expected behavior is that this is still compiled to "-----"

Environment (please complete the following information):

  • OS: Linux
  • Python version: Python 3 compiler, Level 2 cython with Python 2 interpreter
  • Cython version: 0.29.21 (and 0.28.3 and 3.0a6)

Additional context
We're in the process of getting rid of all of the Python 2 stuff... it's a bit sticky if our build tools can't be migrated (our python 2 cython was supporting both python 2 and 3 before)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions