Ticket #470 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

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:


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

Changed 5 years ago by scoder

The expected implementation is

tmp = MyDict()
if not isinstace(tmp, dict):
    tmp = dict(tmp)

Changed 5 years ago by scoder

  • owner changed from somebody to scoder
  • milestone changed from wishlist to 0.12.1

Changed 5 years ago by scoder

  • status changed from new to closed
  • resolution set to fixed

Changed 5 years ago by scoder

Note: See TracTickets for help on using tickets.