[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:


[...]
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 ** 

___
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-03 Thread Stefan Behnel
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:
> 
> 
> [...]
> 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

Stefan

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