Hi Lisandro,

good catch!

Lisandro Dalcin, 10.11.2009 19:10:
> Stefan, the __new__ optimization is not taking place in the case
> below... Any good reason? Am I missing something?
> 
> diff -r 7e9af512c2eb tests/run/tp_new.pyx
> +cdef class Foo:
> +    @classmethod
> +    def new(type cls):
> +        return cls.__new__(cls)
> +
> +def make_new_foo():
> +    """
> +    >>> isinstance(make_new_foo(), Foo)
> +    True
> +    """
> +    return Foo.new()

This isn't because of the __new__ optimisation but because of the way
@classmethod is handled. In the tree, "cls" is typed as Foo, which is
totally wrong for a classmethod. It even overrides your declaration as
"type" and may lead to all sorts of incorrect code, depending on what you
do in your factory.

http://trac.cython.org/cython_trac/ticket/454

I added the test case above (disabled in bugs.txt).

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

Reply via email to