Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#470 closed defect (fixed)

In Py>=2.6, kwargs can be general mappings

Reported by: robertwb Owned by: scoder
Priority: major Milestone: 0.12.1
Component: Code Generation Keywords:
Cc:

Description

See http://www.mail-archive.com/cython-dev@codespeak.net/msg08051.html and http://bugs.python.org/issue1686487

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

Change History (4)

comment:1 Changed 5 years ago by scoder

The expected implementation is

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

comment:2 Changed 5 years ago by scoder

  • Milestone changed from wishlist to 0.12.1
  • Owner changed from somebody to scoder

comment:3 Changed 5 years ago by scoder

  • Resolution set to fixed
  • Status changed from new to closed

comment:4 Changed 5 years ago by scoder

Note: See TracTickets for help on using tickets.