Skip to content

allow access to user_ns in prompt_manager #1151

Closed
wants to merge 1 commit into from

2 participants

@minrk
IPython member
minrk commented Dec 14, 2011

adds UserNSFormatter for falling back on shell.user_ns / builtins for name resolution.

@minrk minrk allow access to user_ns in prompt_manager
adds UserNSFormatter for falling back on shell.user_ns / builtins for name resolution.
4b84f00
@fperez
IPython member
fperez commented Dec 14, 2011

I'm thinking rather than making UserNSFormatter take a shell object, instead we should have something like a MultiDictFormatter, whose constructor takes one or more dicts:

def __init__(self, *namespaces):
  self.namespaces = namespaces

...
for container in self.namespaces:
  etc...

then you simply initialize this guy with

self._formatter = MultiDictFormatter(shell.user_ns, __builtins__)

that way the object is generic and has less direct coupling to the specifics of our shell.

@minrk
IPython member
minrk commented Dec 14, 2011

The only reason I didn't do that was that I wasn't 100% sure that shell.user_ns is a persistent object across %reset and the like.

@minrk
IPython member
minrk commented Dec 14, 2011

Of course, if I instantiate the Formatter inside _render, then that wouldn't be an issue. It would just result in more instantiations, but I'm not sure that's more expensive than "string".format() anyway.

@minrk minrk added a commit that closed this pull request Dec 14, 2011
@minrk minrk allow access to user_ns in prompt_manager
adds UserNSFormatter for falling back on shell.user_ns / builtins for
name resolution.

Closes #1151, rebased to prevent recursive merge.
8822e91
@minrk minrk closed this in 8822e91 Dec 14, 2011
@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
@minrk minrk allow access to user_ns in prompt_manager
adds UserNSFormatter for falling back on shell.user_ns / builtins for
name resolution.

Closes #1151, rebased to prevent recursive merge.
f6325e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.