Skip to content
This repository

Fix wildcard search for updated namespaces #1081

Merged
merged 2 commits into from over 2 years ago

2 participants

Thomas Kluyver Fernando Perez
Thomas Kluyver
Collaborator

Closes #1076.

Fernando Perez
Owner

Looks good, thanks! Merging now.

Fernando Perez fperez merged commit c309789 into from December 01, 2011
Fernando Perez fperez closed this December 01, 2011
Fernando Perez fperez referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  IPython/core/interactiveshell.py
@@ -923,7 +923,7 @@ def init_create_namespaces(self, user_module=None, user_ns=None):
923 923
         # A table holding all the namespaces IPython deals with, so that
924 924
         # introspection facilities can search easily.
925 925
         self.ns_table = {'user_global':self.user_module.__dict__,
926  
-                         'user_local':user_ns,
  926
+                         'user_local':self.user_ns,
927 927
                          'builtin':builtin_mod.__dict__
928 928
                          }
929 929
     
2  IPython/core/magic.py
@@ -693,7 +693,7 @@ def magic_psearch(self, parameter_s=''):
693 693
             return
694 694
 
695 695
         # default namespaces to be searched
696  
-        def_search = ['user','builtin']
  696
+        def_search = ['user_local', 'user_global', 'builtin']
697 697
 
698 698
         # Process options/args
699 699
         opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
18  IPython/core/oinspect.py
@@ -762,13 +762,15 @@ def psearch(self,pattern,ns_table,ns_search=[],
762 762
                                  (name,ns_table.keys()))
763 763
 
764 764
         #print 'type_pattern:',type_pattern # dbg
765  
-        search_result = []
  765
+        search_result, namespaces_seen = set(), set()
766 766
         for ns_name in ns_search:
767 767
             ns = ns_table[ns_name]
768  
-            tmp_res = list(list_namespace(ns,type_pattern,filter,
769  
-                                          ignore_case=ignore_case,
770  
-                                          show_all=show_all))
771  
-            search_result.extend(tmp_res)
772  
-        search_result.sort()
773  
-
774  
-        page.page('\n'.join(search_result))
  768
+            # Normally, locals and globals are the same, so we just check one.
  769
+            if id(ns) in namespaces_seen:
  770
+                continue
  771
+            namespaces_seen.add(id(ns))
  772
+            tmp_res = list_namespace(ns, type_pattern, filter,
  773
+                                    ignore_case=ignore_case, show_all=show_all)
  774
+            search_result.update(tmp_res)
  775
+
  776
+        page.page('\n'.join(sorted(search_result)))
4  IPython/core/tests/test_magic.py
@@ -340,3 +340,7 @@ def doctest_precision():
340 340
     Out[5]: {u}'3.141593e+00'
341 341
     """
342 342
 
  343
+def test_psearch():
  344
+    with tt.AssertPrints("dict.fromkeys"):
  345
+        _ip.run_cell("dict.fr*?")
  346
+
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.