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] "Python global or builtin not a Python object" error when cythonizing a float annotation #4198

Closed
matsjoyce opened this issue May 27, 2021 · 1 comment · Fixed by #4199

Comments

@matsjoyce
Copy link
Contributor

Describe the bug
Cythonizing the code below results in the following error:

Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "<elided>\Scripts\cython.exe\__main__.py", line 7, in <module>
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 714, in setuptools_main
    return main(command_line = 1)
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 732, in main
    result = compile(sources, options)
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 630, in compile
    return compile_multiple(source, options)
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 607, in compile_multiple
    result = run_pipeline(source, options, context=context)
  File "<elided>\lib\site-packages\Cython\Compiler\Main.py", line 505, in run_pipeline
    err, enddata = Pipeline.run_pipeline(pipeline, source)
  File "<elided>\lib\site-packages\Cython\Compiler\Pipeline.py", line 371, in run_pipeline
    data = run(phase, data)
  File "<elided>\lib\site-packages\Cython\Compiler\Pipeline.py", line 351, in run
    return phase(data)
  File "<elided>\lib\site-packages\Cython\Compiler\Pipeline.py", line 52, in generate_pyx_code_stage
    module_node.process_implementation(options, result)
  File "<elided>\lib\site-packages\Cython\Compiler\ModuleNode.py", line 171, in process_implementation
    self.generate_c_code(env, options, result)
  File "<elided>\lib\site-packages\Cython\Compiler\ModuleNode.py", line 483, in generate_c_code
    self.generate_module_init_func(modules[:-1], env, globalstate['init_module'])
  File "<elided>\lib\site-packages\Cython\Compiler\ModuleNode.py", line 2940, in generate_module_init_func
    self.body.generate_execution_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 409, in generate_execution_code
    stat.generate_execution_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 4975, in generate_execution_code
    self.body.generate_execution_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 409, in generate_execution_code
    stat.generate_execution_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 5642, in generate_execution_code
    self.generate_assignment_code(code)
  File "<elided>\lib\site-packages\Cython\Compiler\Nodes.py", line 5939, in generate_assignment_code
    self.lhs.generate_assignment_code(self.rhs, code)
  File "<elided>\lib\site-packages\Cython\Compiler\ExprNodes.py", line 2366, in generate_assignment_code
    assert entry.type.is_pyobject, "Python global or builtin not a Python object"
AssertionError: Python global or builtin not a Python object

To Reproduce
Code to reproduce the behaviour:

# cython: language_level=3

class Foo:
    bar: float = 0.1

Expected behavior
It cythonizes without an error.

Environment:

  • OS: Windows 10
  • Python version: 3.8.7
  • Cython version: 3.0a7

Additional context
The error does not occur when:

  • Using a string annotation (bar: "float" = 0.1)
  • A different type is used (bar: int = 1)
  • No value is given (bar: float)
@da-woods
Copy link
Contributor

da-woods commented May 27, 2021

Thanks for the report. I think this is essentially the same bug as #4196 (although the effect looks slightly different)

da-woods added a commit to da-woods/cython that referenced this issue May 27, 2021
da-woods added a commit to da-woods/cython that referenced this issue May 27, 2021
da-woods added a commit to da-woods/cython that referenced this issue May 27, 2021
scoder pushed a commit that referenced this issue Jun 22, 2021
@scoder scoder added this to the 3.0 milestone Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants