[Cython] [cython-users] Confusing error when trying to get non-existent attribute of cimported library
Robert Bradshaw
robertwb at gmail.com
Wed Aug 12 22:32:57 CEST 2015
On Tue, Aug 11, 2015 at 9:10 PM, Antony Lee <antony.lee at berkeley.edu> wrote:
> Compiling and running
>
> from libc cimport math
> def f():
> print(math.abs(-1)) # oops, should be fabs
>
> results in NameError, name 'math' is not defined. I guess that this results
> from the fact that cimported names and other names effectively live in
> different namespaces, but this is a bit confusing.
Agreed, this confusing.
We do want to support
from libc cimport math
import math
math.somthing_that_only_exists_in_the_python_module()
I'm not sure we need to support
from libc cimport math
globals()['math'] = whatever
math.somthing_that_only_exists_in_whatever
We've long wanted to restrict arbitrary writes to a Cython module's
global namespace... and of course such writes already aren't respected
by compile-time bindings, so is anyone opposed to making this an
error?
- Robert
More information about the cython-devel
mailing list