Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Py>=2.6, kwargs can be general mappings #1030

Closed
robertwb opened this issue Dec 27, 2009 · 4 comments
Closed

In Py>=2.6, kwargs can be general mappings #1030

robertwb opened this issue Dec 27, 2009 · 4 comments

Comments

@robertwb
Copy link
Contributor

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

Migrated from http://trac.cython.org/ticket/470

@robertwb
Copy link
Contributor Author

scoder commented

The expected implementation is

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

@robertwb
Copy link
Contributor Author

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

@robertwb
Copy link
Contributor Author

scoder changed resolution to fixed
status from new to closed
commented

Implemented here:

http://hg.cython.org/cython-devel/rev/df9b7285ec6a

@robertwb
Copy link
Contributor Author

scoder commented

Better implementation here:

http://hg.cython.org/cython-devel/rev/5d1ea5364347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant