[IPython-dev] IPython1 API design question

Brian Granger ellisonbg.net at gmail.com
Fri Feb 8 17:33:06 EST 2008


> What about two push/pull method pairs...
>
> def push(self, **namespace):
>    self.pushEx(namespace, block=<current_blocking_mode>, targets='all')
> def pull(self, *keys):
>    self.pullEx(keys, block= <current_blocking_mode>, targets='all')
>
> and
>
> pushEx(self, ns, block=True, target='all')
> pullEx(self, keys, block=True, target='all')

My current thinking is to basically do something like this.  Most of
the API (that developers see) would have the more verbose versions
pushEx/pullEx, but the API that users see could be stateful and take
**/* arguments.  But one important point that I realized later is that
most of the API cannot be stateful, so this solution only work in
certain places where it is OK to hold state.

Brian

> Obviously I haven't put a lot of thought into the names, but the idea
> is to provide a convenience method for the "expected" use case and an
> extended method with more options.
>
> barry
>
>
> On Feb 8, 2008 2:12 PM, Stefan van der Walt <stefan at sun.ac.za> wrote:
> > On Fri, Feb 08, 2008 at 09:16:25AM -0700, Brian Granger wrote:
> > > The alternate API would look some thing like this:
> > >
> > > push(self, ns, block=True, targets='all')
> > > pull(self, keys, block=True, targets='all')
> > >
> > > And be used:
> > >
> > > push(dict(a=10,b=30), block=False)      # targets = 'all'
> > > pull(('a','b'))     # block=True, tagets='all'
> > >
> > > the main disadvantage is that a user has to manually build the dict
> > > and tuple.  For pull, we could do a test to see if keys is a string
> > > and build the tuple for then, but for the dict, they really have to
> > > build it using dict or {}
> > >
> > > So, which of these approaches seems better, both from the development
> > > and user's perspective?  Thoughts?
> >
> > For what it's worth, I like the idea of pushing namespaces.  With the
> > current system, you can do (as a random example)
> >
> >   push(*_ip.user_ns)
> >
> > but then you have to make sure that the dict doesn't contain some
> > special keywords.  I imagine it would be better to shield the user
> > from such unexpected side-effects.
> >
> > Regards
> > Stéfan
> >
> > _______________________________________________
> > IPython-dev mailing list
> > IPython-dev at scipy.org
> > http://lists.ipython.scipy.org/mailman/listinfo/ipython-dev
> >
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://lists.ipython.scipy.org/mailman/listinfo/ipython-dev
>



More information about the IPython-dev mailing list