##// END OF EJS Templates
Remove alias_table
Thomas Kluyver -
Show More
@@ -150,7 +150,6 b' class AliasManager(Configurable):'
150
150
151 def __init__(self, shell=None, **kwargs):
151 def __init__(self, shell=None, **kwargs):
152 super(AliasManager, self).__init__(shell=shell, **kwargs)
152 super(AliasManager, self).__init__(shell=shell, **kwargs)
153 self.alias_table = {}
154 self.init_exclusions()
153 self.init_exclusions()
155 self.init_aliases()
154 self.init_aliases()
156
155
@@ -211,6 +210,14 b' class AliasManager(Configurable):'
211 if name in self.no_alias:
210 if name in self.no_alias:
212 raise InvalidAliasError("The name %s can't be aliased "
211 raise InvalidAliasError("The name %s can't be aliased "
213 "because it is a keyword or builtin." % name)
212 "because it is a keyword or builtin." % name)
213 try:
214 caller = self.shell.magics_manager.magics['line'][name]
215 except KeyError:
216 pass
217 else:
218 if not isinstance(caller, AliasCaller):
219 raise InvalidAliasError("The name %s can't be aliased "
220 "because it is another magic command." % name)
214 if not (isinstance(cmd, basestring)):
221 if not (isinstance(cmd, basestring)):
215 raise InvalidAliasError("An alias command must be a string, "
222 raise InvalidAliasError("An alias command must be a string, "
216 "got: %r" % cmd)
223 "got: %r" % cmd)
@@ -223,3 +230,8 b' class AliasManager(Configurable):'
223 return caller.cmd
230 return caller.cmd
224 else:
231 else:
225 raise ValueError('%s is not an alias' % name)
232 raise ValueError('%s is not an alias' % name)
233
234 def is_alias(self, name):
235 """Return whether or not a given name has been defined as an alias"""
236 caller = self.shell.magics_manager.magics['line'].get(name, None)
237 return isinstance(caller, AliasCaller)
@@ -1363,9 +1363,7 b' class InteractiveShell(SingletonConfigurable):'
1363 namespaces = [ ('Interactive', self.user_ns),
1363 namespaces = [ ('Interactive', self.user_ns),
1364 ('Interactive (global)', self.user_global_ns),
1364 ('Interactive (global)', self.user_global_ns),
1365 ('Python builtin', builtin_mod.__dict__),
1365 ('Python builtin', builtin_mod.__dict__),
1366 ('Alias', self.alias_manager.alias_table),
1367 ]
1366 ]
1368 alias_ns = self.alias_manager.alias_table
1369
1367
1370 # initialize results to 'null'
1368 # initialize results to 'null'
1371 found = False; obj = None; ospace = None; ds = None;
1369 found = False; obj = None; ospace = None; ds = None;
@@ -1404,8 +1402,6 b' class InteractiveShell(SingletonConfigurable):'
1404 # If we finish the for loop (no break), we got all members
1402 # If we finish the for loop (no break), we got all members
1405 found = True
1403 found = True
1406 ospace = nsname
1404 ospace = nsname
1407 if ns == alias_ns:
1408 isalias = True
1409 break # namespace loop
1405 break # namespace loop
1410
1406
1411 # Try to see if it's magic
1407 # Try to see if it's magic
@@ -2305,7 +2301,6 b' class InteractiveShell(SingletonConfigurable):'
2305 def init_alias(self):
2301 def init_alias(self):
2306 self.alias_manager = AliasManager(shell=self, parent=self)
2302 self.alias_manager = AliasManager(shell=self, parent=self)
2307 self.configurables.append(self.alias_manager)
2303 self.configurables.append(self.alias_manager)
2308 self.ns_table['alias'] = self.alias_manager.alias_table,
2309
2304
2310 #-------------------------------------------------------------------------
2305 #-------------------------------------------------------------------------
2311 # Things related to extensions
2306 # Things related to extensions
@@ -192,7 +192,7 b' class OSMagics(Magics):'
192 try:
192 try:
193 # Removes dots from the name since ipython
193 # Removes dots from the name since ipython
194 # will assume names with dots to be python.
194 # will assume names with dots to be python.
195 if ff not in self.shell.alias_manager:
195 if not self.shell.alias_manager.is_alias(ff):
196 self.shell.alias_manager.define_alias(
196 self.shell.alias_manager.define_alias(
197 ff.replace('.',''), ff)
197 ff.replace('.',''), ff)
198 except InvalidAliasError:
198 except InvalidAliasError:
@@ -48,16 +48,16 b' class DummyMagics(magic.Magics): pass'
48 def test_rehashx():
48 def test_rehashx():
49 # clear up everything
49 # clear up everything
50 _ip = get_ipython()
50 _ip = get_ipython()
51 _ip.alias_manager.alias_table.clear()
51 _ip.alias_manager.clear_aliases()
52 del _ip.db['syscmdlist']
52 del _ip.db['syscmdlist']
53
53
54 _ip.magic('rehashx')
54 _ip.magic('rehashx')
55 # Practically ALL ipython development systems will have more than 10 aliases
55 # Practically ALL ipython development systems will have more than 10 aliases
56
56
57 nt.assert_true(len(_ip.alias_manager.alias_table) > 10)
57 nt.assert_true(len(_ip.alias_manager.aliases) > 10)
58 for key, val in _ip.alias_manager.alias_table.iteritems():
58 for name, cmd in _ip.alias_manager.aliases:
59 # we must strip dots from alias names
59 # we must strip dots from alias names
60 nt.assert_not_in('.', key)
60 nt.assert_not_in('.', name)
61
61
62 # rehashx must fill up syscmdlist
62 # rehashx must fill up syscmdlist
63 scoms = _ip.db['syscmdlist']
63 scoms = _ip.db['syscmdlist']
@@ -369,7 +369,7 b' class TerminalInteractiveShell(InteractiveShell):'
369
369
370
370
371 for name, cmd in aliases:
371 for name, cmd in aliases:
372 self.alias_manager.define_alias(name, cmd)
372 self.alias_manager.soft_define_alias(name, cmd)
373
373
374 #-------------------------------------------------------------------------
374 #-------------------------------------------------------------------------
375 # Things related to the banner and usage
375 # Things related to the banner and usage
General Comments 0
You need to be logged in to leave comments. Login now