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

ctx is a defined function parameter that's always overwritten, i.e. never in kwargs #131

Open
jimdewees opened this issue Oct 24, 2018 · 4 comments

Comments

@jimdewees
Copy link

ctx = kwargs.get('ctx')

>>> class C(object):
...     def __init__(self, ctx=None, *args, **kwargs):
...         print(ctx, kwargs, kwargs.get('ctx'))
...
>>> try:
...     c1 = C('this', ctx='that')
... except TypeError as err:
...     print(err)
...
__init__() got multiple values for argument 'ctx'
>>> try:
...     c2 = C(ctx='this', **{'ctx': 'that'})
... except TypeError as err:
...     print(err)
...
type object got multiple values for keyword argument 'ctx'
>>> c3 = C('this', _ctx='that')
this {'_ctx': 'that'} None
>>> c4 = C(ctx='this is not in kwargs')
this is not in kwargs {} None
>>> c5 = C(**{'ctx': 'neither is this'})
neither is this {} None
@sphaero
Copy link
Contributor

sphaero commented Oct 25, 2018

so what are you suggesting?

@jimdewees
Copy link
Author

The docstring for zmq.Context.instance provides a good implementation example.

@sphaero
Copy link
Contributor

sphaero commented Dec 11, 2018

You're not very verbose. Are you suggesting that:

ctx = kwargs.get('ctx')
if ctx == None:
    ctx = zmq.Context()
self._ctx = ctx

should be reduced to

self._ctx = ctx or zmq.Context()

@fieldOfView
Copy link
Contributor

fieldOfView commented Dec 11, 2018

That would fix the issue that you are trying to get ctx from the kwargs dict, whereas it is defined as a proper keyword argument in the __init__ method definition.

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

No branches or pull requests

3 participants