> Ideally, I'd like some syntax that could be run as valid Python (no
> syntax or name errors) but declare a specific variable to be a type,
> which is more powerful than using assignment + type inference (for
> example, one could add several python ints to a and it would do the
> right thing).

Overloading += and + would help, but I know that's not the point :-)

Perhaps then a variant on the SAGE approach with vars("x") or similar?
Using a string for the variable name makes it more natural for Python
users since they know x is not declared yet, and you can already do
locals()["x"] which is almost as "wierd". So

typed("x", cython.types.int, "s,w", cython.types.ptr(cython.types.char))
w = "ok"
x = "compiler error"

If consistency is important then even

@cython(args=("x", cython.types.int), ret=cython.types.int, except=-1)
def foo(x):
  typed("sq", cython.types.int)
  square = x*x
  return sq

But it might be too verbose.

Similar example not typing, for comparison:

def bar(x: cython.types.int):
  assert fullycompiled # True if no object references made in block and
sub-blocks
  sq = x * x
  assert native(sq) # Always True because of fully-compiled, but...
  return sq

Doesn't seem to be anything wrong with combining both and let the user
pick (guess that is the meaning of "type inference" - but I see the issues
clearer now, guess I'm lagging behind a bit).

Still - if there are two modes of operations:
1) Don't type variables but use inference heavily
2) Explicitly typed variable names

then perhaps it isn't critical that 2) has a valid Python syntax if 1) has
it? (Can always add some candy to current syntax, like allowing "for int i
in range(..." and make the "cdef" keyword optional).

Dag Sverre

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to