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

Using types like `cython.int` as names should be an error #2003

Open
lxkain opened this Issue Nov 15, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@lxkain

lxkain commented Nov 15, 2017

Under regular python, I can do:

import cython
a = cython.int

but this fails when executed in a jupyter notebook:

%%cython -a  

import cython
a = cython.int

with:


NameError Traceback (most recent call last)
in ()
----> 1 get_ipython().run_cell_magic('cython', '-a ', '\nimport cython\n\nint = cython.int')

~/miniconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
2101 magic_arg_s = self.var_expand(line, stack_depth)
2102 with self.builtin_trap:
-> 2103 result = fn(magic_arg_s, cell)
2104 return result
2105

in cython(self, line, cell)

~/miniconda3/lib/python3.6/site-packages/IPython/core/magic.py in (f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):

~/miniconda3/lib/python3.6/site-packages/Cython/Build/IpythonMagic.py in cython(self, line, cell)
329 quiet=args.quiet)
330
--> 331 module = imp.load_dynamic(module_name, module_path)
332 self._import_all(module)
333

~/miniconda3/lib/python3.6/imp.py in load_dynamic(name, path, file)
341 spec = importlib.machinery.ModuleSpec(
342 name=name, loader=loader, origin=path)
--> 343 return _load(spec)
344
345 else:

~/miniconda3/lib/python3.6/importlib/_bootstrap.py in _load(spec)

~/miniconda3/lib/python3.6/importlib/_bootstrap.py in _load_unlocked(spec)

~/miniconda3/lib/python3.6/importlib/_bootstrap.py in module_from_spec(spec)

~/miniconda3/lib/python3.6/importlib/_bootstrap_external.py in create_module(self, spec)

~/miniconda3/lib/python3.6/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

_cython_magic_327e2d2f604f7991cec4f17a998933f6.pyx in init _cython_magic_327e2d2f604f7991cec4f17a998933f6()

NameError: name 'cython' is not defined

Take away the top magic line and it works.

@scoder

This comment has been minimized.

Show comment
Hide comment
@scoder

scoder Nov 16, 2017

Contributor

Thanks for the report, but to me it feels like this should not be implemented as a feature. What would it mean to assign the C type int to a variable? What is the use case?

Contributor

scoder commented Nov 16, 2017

Thanks for the report, but to me it feels like this should not be implemented as a feature. What would it mean to assign the C type int to a variable? What is the use case?

@lxkain

This comment has been minimized.

Show comment
Hide comment
@lxkain

lxkain Nov 16, 2017

I want to use it as a type definition later on, in an effort to maintain pure python mode; e.g. I want to write something like

if cython.compiled:
  my_int_t = cython.int
else:
  my_int_t = int

lxkain commented Nov 16, 2017

I want to use it as a type definition later on, in an effort to maintain pure python mode; e.g. I want to write something like

if cython.compiled:
  my_int_t = cython.int
else:
  my_int_t = int

@scoder scoder changed the title from load_ext Cython does not support cython.int to Using types like `cython.int` as names should be an error Nov 22, 2017

@scoder

This comment has been minimized.

Show comment
Hide comment
@scoder

scoder Nov 22, 2017

Contributor

cython.int is essentially an alias for int when not compiled.

Contributor

scoder commented Nov 22, 2017

cython.int is essentially an alias for int when not compiled.

@lxkain

This comment has been minimized.

Show comment
Hide comment
@lxkain

lxkain Nov 22, 2017

OK, I was trying to be clever trying to maintain pure python mode, but I think we are not quite there yet. Looking forward to 0.28 and beyond!

lxkain commented Nov 22, 2017

OK, I was trying to be clever trying to maintain pure python mode, but I think we are not quite there yet. Looking forward to 0.28 and beyond!

@lxkain lxkain closed this Nov 22, 2017

@scoder

This comment has been minimized.

Show comment
Hide comment
@scoder

scoder Nov 24, 2017

Contributor

Reopening as it should still be an error instead of crashing or passing silently.

Contributor

scoder commented Nov 24, 2017

Reopening as it should still be an error instead of crashing or passing silently.

@scoder scoder reopened this Nov 24, 2017

@scoder scoder added the defect label Nov 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment