Re: [Cython] In Py=2.6, kwargs can be general mappings

2009-12-26 Thread Robert Bradshaw
On Dec 22, 2009, at 6:43 AM, Stefan Behnel wrote:


 Lisandro Dalcín, 22.12.2009 15:33:
 The support for new feature in core CPython is at Python/ceval.c,
 function ext_do_call().

 Ah, I get it. So the problem is that this is done as part of the / 
 call/
 (and basically by the interpreter), for which Cython has its own code.

 I think that's worth a trac ticket, then, although I consider it a  
 rather
 minor feature.

Yep, we should support this (though I agree that it's minor).

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

- Robert

___
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev


[Cython] In Py=2.6, kwargs can be general mappings

2009-12-22 Thread Lisandro Dalcín
While testing type inference in mpi4py, I noticed that code like the
one below is failing in the last line. It seems that in  Py=2.6,
Python makes a coercion on kw and builds an actual dict instance
before calling.

class Foo:
def view(self, **kw):
print (kw)
for k in kw.keys():
print (k)

Foo().view(a=0, b=1, c=2)

class MyDict(object):
def __getitem__(self, k):
assert k == 'a'
return 7
def keys(self):
return ['a']

Foo().view(**MyDict()) # -- Here is the issue


Running on Py=2.6, the code above gives:

{'a': 0, 'c': 2, 'b': 1}
a
c
b
{'a': 7}
a

so that makes me think that at some point Python is building a tmp
dict out of MyDict instance.



-- 
Lisandro Dalcín
---
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
___
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev


Re: [Cython] In Py=2.6, kwargs can be general mappings

2009-12-22 Thread Lisandro Dalcín
On Tue, Dec 22, 2009 at 10:58 AM, Stefan Behnel stefan...@behnel.de wrote:

 Lisandro Dalcín, 22.12.2009 14:47:
 While testing type inference in mpi4py, I noticed that code like the
 one below is failing in the last line. It seems that in  Py=2.6,
 Python makes a coercion on kw and builds an actual dict instance
 before calling.

 class Foo:
     def view(self, **kw):
         print (kw)
         for k in kw.keys():
             print (k)

 Foo().view(a=0, b=1, c=2)

 class MyDict(object):
     def __getitem__(self, k):
         assert k == 'a'
         return 7
     def keys(self):
         return ['a']

 Foo().view(**MyDict()) # -- Here is the issue


 Running on Py=2.6, the code above gives:

 {'a': 0, 'c': 2, 'b': 1}
 a
 c
 b
 {'a': 7}
 a

 so that makes me think that at some point Python is building a tmp
 dict out of MyDict instance.

 Interesting. So, what's your point? It didn't work before and it works now
 by passing in a real dict. Does this impact Cython in any way?


Sorry, I was not clear enough. My point is that the line below fails:

Foo().view(**MyDict())

see yourself:



In [1]: import pyximport; pyximport.install()

In [2]: import kargs
{'a': 0, 'c': 2, 'b': 1}
a
c
b
---
ImportError   Traceback (most recent call last)

/u/dalcinl/tmp/ipython console in module()
...
--- 18 Foo().view(**MyDict())

ImportError: Building module failed: ['TypeError: keyword list must be
a dictionary\n']


So, in short Cython does not follow Python (=2.6, including 3.x).
Cython should generate some extra code to support this new Python
feature:

tmp =MyDict()
if not isinstace(tmp, dict):
tmp = dict(tmp)
Foo().view(**tmp)


PS: The support for new feature in core CPython is at Python/ceval.c,
function ext_do_call(). This feature was tracked here:
http://bugs.python.org/issue1686487


-- 
Lisandro Dalcín
---
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
___
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev


Re: [Cython] In Py=2.6, kwargs can be general mappings

2009-12-22 Thread Stefan Behnel

Lisandro Dalcín, 22.12.2009 15:33:
 The support for new feature in core CPython is at Python/ceval.c,
 function ext_do_call().

Ah, I get it. So the problem is that this is done as part of the /call/ 
(and basically by the interpreter), for which Cython has its own code.

I think that's worth a trac ticket, then, although I consider it a rather 
minor feature.

Stefan
___
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev