From 89108b6425c831b08fc251661cca63406f77d442 2013-09-19 17:56:11 From: Thomas Kluyver Date: 2013-09-19 17:56:11 Subject: [PATCH] Remove alias_table --- diff --git a/IPython/core/alias.py b/IPython/core/alias.py index 3e9bfed..07faa2c 100644 --- a/IPython/core/alias.py +++ b/IPython/core/alias.py @@ -150,7 +150,6 @@ class AliasManager(Configurable): def __init__(self, shell=None, **kwargs): super(AliasManager, self).__init__(shell=shell, **kwargs) - self.alias_table = {} self.init_exclusions() self.init_aliases() @@ -211,6 +210,14 @@ class AliasManager(Configurable): if name in self.no_alias: raise InvalidAliasError("The name %s can't be aliased " "because it is a keyword or builtin." % name) + try: + caller = self.shell.magics_manager.magics['line'][name] + except KeyError: + pass + else: + if not isinstance(caller, AliasCaller): + raise InvalidAliasError("The name %s can't be aliased " + "because it is another magic command." % name) if not (isinstance(cmd, basestring)): raise InvalidAliasError("An alias command must be a string, " "got: %r" % cmd) @@ -223,3 +230,8 @@ class AliasManager(Configurable): return caller.cmd else: raise ValueError('%s is not an alias' % name) + + def is_alias(self, name): + """Return whether or not a given name has been defined as an alias""" + caller = self.shell.magics_manager.magics['line'].get(name, None) + return isinstance(caller, AliasCaller) diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index a65a2a8..ffbbd7e 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1363,9 +1363,7 @@ class InteractiveShell(SingletonConfigurable): namespaces = [ ('Interactive', self.user_ns), ('Interactive (global)', self.user_global_ns), ('Python builtin', builtin_mod.__dict__), - ('Alias', self.alias_manager.alias_table), ] - alias_ns = self.alias_manager.alias_table # initialize results to 'null' found = False; obj = None; ospace = None; ds = None; @@ -1404,8 +1402,6 @@ class InteractiveShell(SingletonConfigurable): # If we finish the for loop (no break), we got all members found = True ospace = nsname - if ns == alias_ns: - isalias = True break # namespace loop # Try to see if it's magic @@ -2305,7 +2301,6 @@ class InteractiveShell(SingletonConfigurable): def init_alias(self): self.alias_manager = AliasManager(shell=self, parent=self) self.configurables.append(self.alias_manager) - self.ns_table['alias'] = self.alias_manager.alias_table, #------------------------------------------------------------------------- # Things related to extensions diff --git a/IPython/core/magics/osm.py b/IPython/core/magics/osm.py index d23bb1f..8e35d45 100644 --- a/IPython/core/magics/osm.py +++ b/IPython/core/magics/osm.py @@ -192,7 +192,7 @@ class OSMagics(Magics): try: # Removes dots from the name since ipython # will assume names with dots to be python. - if ff not in self.shell.alias_manager: + if not self.shell.alias_manager.is_alias(ff): self.shell.alias_manager.define_alias( ff.replace('.',''), ff) except InvalidAliasError: diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 7740524..8954722 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -48,16 +48,16 @@ class DummyMagics(magic.Magics): pass def test_rehashx(): # clear up everything _ip = get_ipython() - _ip.alias_manager.alias_table.clear() + _ip.alias_manager.clear_aliases() del _ip.db['syscmdlist'] _ip.magic('rehashx') # Practically ALL ipython development systems will have more than 10 aliases - nt.assert_true(len(_ip.alias_manager.alias_table) > 10) - for key, val in _ip.alias_manager.alias_table.iteritems(): + nt.assert_true(len(_ip.alias_manager.aliases) > 10) + for name, cmd in _ip.alias_manager.aliases: # we must strip dots from alias names - nt.assert_not_in('.', key) + nt.assert_not_in('.', name) # rehashx must fill up syscmdlist scoms = _ip.db['syscmdlist'] diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 3a7c93a..5b034d0 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -369,7 +369,7 @@ class TerminalInteractiveShell(InteractiveShell): for name, cmd in aliases: - self.alias_manager.define_alias(name, cmd) + self.alias_manager.soft_define_alias(name, cmd) #------------------------------------------------------------------------- # Things related to the banner and usage