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

allow access to user_ns in prompt_manager #1151

Closed
wants to merge 1 commit into from

Conversation

minrk
Copy link
Member

@minrk minrk commented Dec 14, 2011

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

adds UserNSFormatter for falling back on shell.user_ns / builtins for name resolution.
@fperez
Copy link
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
Copy link
Member Author

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
Copy link
Member Author

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 closed this in 8822e91 Dec 14, 2011
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
adds UserNSFormatter for falling back on shell.user_ns / builtins for
name resolution.

Closes ipython#1151, rebased to prevent recursive merge.
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

Successfully merging this pull request may close these issues.

None yet

2 participants