Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] -3 does not set language level in Cython 3 #5484

Closed
lithomas1 opened this issue Jun 13, 2023 · 3 comments · Fixed by #5487
Closed

[BUG] -3 does not set language level in Cython 3 #5484

lithomas1 opened this issue Jun 13, 2023 · 3 comments · Fixed by #5487
Labels

Comments

@lithomas1
Copy link
Contributor

Describe the bug

The -3 flag does not set language level to 3.

When compiling some code with the always_allow_keywords directive set to true with Cython 3, Cython doesn't set the language level to 3 even though -3 is passed, and infers the language level as 3str causing the compile failure.

See logs I have attached below.

Code to reproduce the behaviour:

cython -M --fast-fail -3 --include-dir /home/runner/work/pandas/pandas/build/cp310/pandas/_libs/tslibs '-X always_allow_keywords=true' /home/runner/work/pandas/pandas/pandas/_libs/tslibs/offsets.pyx -o pandas/_libs/tslibs/offsets.cpython-310-x86_64-linux-gnu.so.p/pandas/_libs/tslibs/offsets.pyx.c
  /home/runner/micromamba/envs/test/lib/python3.10/site-packages/Cython/Compiler/Main.py:370: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/runner/work/pandas/pandas/pandas/_libs/tslibs/offsets.pxd
    tree = Parsing.p_module(s, pxd, full_module_name)

  Error compiling Cython file:
  ------------------------------------------------------------
  ...

      def get_rule_code_suffix(self) -> str:
          prefix = self._get_suffix_prefix()
          month = MONTH_ALIASES[self.startingMonth]
          weekday = int_to_weekday[self.weekday]
          return f"{prefix}-{month}-{weekday}"

Expected behaviour

Language level should be inferred as 3

OS

Ubuntu 22.04.2

Python version

3.10.11

Cython version

Cython 3.0.0b3

Additional context

No response

@da-woods
Copy link
Contributor

Thanks for the report. Can reproduce this. Just to make clear (since it wasn't 100% clear to me from the issue) it's the '-X ...' argument that seems to trigger it. A simple cython -3 filename.pyx looks to work fine.

@matusvalo
Copy link
Contributor

Issue is caused by following lines:

if 'language_level' in directives and 'language_level' not in kw:
options['language_level'] = directives['language_level']

when -X switch is used, directives variable contains dictionary with directives containing also language_level set to None. Hence the options dictionary with key language_level is set to None instead of 3.

@lithomas1
Copy link
Contributor Author

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants