Skip to content

[BUG] cpdef module-level variables not exposed to Python #3959

@leofang

Description

@leofang

Describe the bug

For a cpdef variable declared at the module level like this

# test_cpdef_module_var.pyx

...
cpdef str abc = 'this is abc'
...

I would expect that I can access this Python string in the Python space simply by test_cpdef_module_var.abc. However, this appears to be not possible, and we had to work around it by explicitly declaring a Python object referencing it:

# test_cpdef_module_var.pyx

...
cpdef str _abc = 'this is abc'
abc = _abc
...

which is both counterintuitive and cumbersome. I tried searching in the issue tracker but it doesn't seem to be reported yet, and the closest report I found is this (#656) but not exactly the same, so I hope I am simply missing something obvious...

To Reproduce
See above.

Expected behavior
See above.

Environment (please complete the following information):

  • OS: Linux
  • Python version: 3.7.8
  • Cython version: 0.29.21

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions