[Cython] Possible bug when using cython -Wextra

2013-02-07 Thread Samuele Kaplun
Hello,

I am not sure if this is a bug or it is the intended behaviour, however, 
consider for example this snippet:

[...]
def test():
cdef int i
for i from 0 <= i < 10:
print "foo"
[...]

If I save it into x.pyx and compile it with:

$ cython -Wextra x.pyx

I obtain the warning:
[...]
warning: x.pyx:2:13: Unused entry 'i'
[...]

IMHO, this is a false positive since the i variable is indeed used as a 
counter in the loop. I guess cython considers it unused due to the fact that 
it does not appear on the right hand side of an assignment nor it is further 
used as an argument in a function, isn’t it?

Best regards,
    Samuele
-- 
Samuele Kaplun
Invenio Developer ** <http://invenio-software.org/>
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Possible bug when using cython -Wextra

2013-02-07 Thread Samuele Kaplun
Dear Stefan,

In data giovedì 7 febbraio 2013 12:11:47, Stefan Behnel ha scritto:
> > [...]
> > 
> > def test():
> > cdef int i
> > 
> > for i from 0 <= i < 10:
> > print "foo"
> > 
> > [...]
> 
> Yes, it actually is an unused variable in your code. There is no reference
> to it, only assignments.

mmh. But is it used albeit indirectly. Then what pattern would you suggest in 
this case (i.e. to repeat a certain body a given number of times), in order to 
avoid such warning?

Cheers (and thanks for your time!),
Samuele

-- 
Samuele Kaplun
Invenio Developer ** <http://invenio-software.org/>
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


[Cython] Possible bug (or wrong documentation) WRT "not None"

2014-12-03 Thread Samuele Kaplun
Hi!

I would like to report what I think is a possible bug (in cython or 
corresponding documentation).

According to:
<http://docs.cython.org/src/userguide/extension_types.html#extension-types-and-none>

[...]
The self parameter of a method of an extension type is guaranteed never to be 
None.
[...]

However given this snippet:
[...]
cdef class test:
def __sub__(self, test rhs not None):
print "self is %s" % repr(self), "rhs is %s" % repr(rhs)
[...]

If I then load it python:
In [1]: import test
In [2]: x = test.test()
In [3]: None - x
self is None rhs is 

Thus showing that in this case "self" was actually initialized with None.

If I explictly add "not None" as in:
[...]
cdef class test:
def __sub__(self not None, test rhs not None):
print "self is %s" % repr(self), "rhs is %s" % repr(rhs)
[...]
In [3]: None - x
TypeError: Argument 'self' must not be None
[...]

Which is good.

If I instead add "test self" as in:
[...]
cdef class test:
def __sub__(test self not None, test rhs not None):
print "self is %s" % repr(self), "rhs is %s" % repr(rhs)
[...]
In [3]: None - x
TypeError: Argument 'self' has incorrect type (expected test.test, got 
NoneType)
[...]

What's worse is that if I use "test self" (without not None), the same 
TypeError is not raised:
[...]
cdef class test:
def __sub__(test self, test rhs not None):
print "self is %s" % repr(self), "rhs is %s" % repr(rhs)
[...]
In [3]: None - x
self is None rhs is 

Thus we have:
self -> not respecting None-checking (in disagreement with Documentation)
self not None ->  OK
test self -> not respecting type-checking!
test self non None -> OK (respecting type-checking, hence None-checking).

Hope that helps. Cheers,
Samuele

-- 
Samuele Kaplun
Invenio Developer ** <http://invenio-software.org/>

___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Possible bug (or wrong documentation) WRT "not None"

2014-12-04 Thread Samuele Kaplun
Dear Stefan,

In data mercoledì 3 dicembre 2014 16:44:13, Stefan Behnel ha scritto:
> Samuele Kaplun schrieb am 02.12.2014 um 14:13:
> > I would like to report what I think is a possible bug (in cython or
> > corresponding documentation).
> > 
> > According to:
> > <http://docs.cython.org/src/userguide/extension_types.html#extension-types
> > -and-none>
> > 
> > [...]
> > The self parameter of a method of an extension type is guaranteed never to
> > be None.
> > [...]
> > 
> > However given this snippet:
> > [...]
> > 
> > cdef class test:
> > def __sub__(self, test rhs not None):
> > print "self is %s" % repr(self), "rhs is %s" % repr(rhs)
> > 
> > [...]
> 
> http://docs.cython.org/src/userguide/special_methods.html#arithmetic-methods

thanks for the pointer. Then I guess the documentation could be improved by 
e.g. saying something similar to:

[...]
The self parameter of a method of an extension type is guaranteed never to be 
None. (Note: arithmetic methods might be an exception to this rule. 
[http://docs.cython.org/src/userguide/special_methods.html#arithmetic-methods]).
[...]

Cheers,
Samuele
-- 
Samuele Kaplun
Invenio Developer ** <http://invenio-software.org/>

___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel