Repository: ipython/ipython

Issue:
%clear doesn't work after %reset
**Problem:** Normally, when I use `%clear` on IPython it works perfectly, clears the screen, but when I use `%reset` to reset my IPython shell, and then I try to use `%clear` it says:

> UsageError: Line magic function `%clear` not found.

Also, before using the `%reset` command, when I type `%` and press tab for auto completion, I can see `%clear` is one of the suggestions, but after the `%reset` command, `%clear` is not in the suggestions anymore..

**System info:**

```
{'commit_hash': '<not found>',
 'commit_source': '(none found)',
 'default_encoding': 'UTF-8',
 'ipython_path': '/usr/lib/python3.7/site-packages/IPython',
 'ipython_version': '7.1.1',
 'os_name': 'posix',
 'platform': 'Linux-4.19.8-arch1-1-ARCH-x86_64-with-arch-Arch-Linux',
 'sys_executable': '/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.7.1 (default, Oct 22 2018, 10:41:28) \n[GCC 8.2.1 20180831]'}
```


%clear doesn't work after %reset
**Problem:** Normally, when I use `%clear` on IPython it works perfectly, clears the screen, but when I use `%reset` to reset my IPython shell, and then I try to use `%clear` it says:

> UsageError: Line magic function `%clear` not found.

Also, before using the `%reset` command, when I type `%` and press tab for auto completion, I can see `%clear` is one of the suggestions, but after the `%reset` command, `%clear` is not in the suggestions anymore..

**System info:**

```
{'commit_hash': '<not found>',
 'commit_source': '(none found)',
 'default_encoding': 'UTF-8',
 'ipython_path': '/usr/lib/python3.7/site-packages/IPython',
 'ipython_version': '7.1.1',
 'os_name': 'posix',
 'platform': 'Linux-4.19.8-arch1-1-ARCH-x86_64-with-arch-Arch-Linux',
 'sys_executable': '/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.7.1 (default, Oct 22 2018, 10:41:28) \n[GCC 8.2.1 20180831]'}
```




Discussion:
It seems like this can be fixed by adding
`self.init_alias()`
at line 1435 of core/interactiveshell.py under the reset function after
`# Restore the default and user aliases`
`self.alias_manager.clear_aliases()`
`self.alias_manager.init_aliases()`

My only qualm with recommending this fix is that I don't know what the intended behavior here is (as I haven't contributed to this repo before). In the meantime, you can always get around this bug by using `!clear` instead of `%clear` if that helps.
It seems like this can be fixed by adding
`self.init_alias()`
at line 1435 of core/interactiveshell.py under the reset function after
`# Restore the default and user aliases`
`self.alias_manager.clear_aliases()`
`self.alias_manager.init_aliases()`

My only qualm with recommending this fix is that I don't know what the intended behavior here is (as I haven't contributed to this repo before). In the meantime, you can always get around this bug by using `!clear` instead of `%clear` if that helps.

Resolving patch:
diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -1433,6 +1433,13 @@ def reset(self, new_session=True):
         self.alias_manager.clear_aliases()
         self.alias_manager.init_aliases()
 
+        # Now define aliases that only make sense on the terminal, because they
+        # need direct access to the console in a way that we can't emulate in
+        # GUI or web frontend
+        if os.name == 'posix':
+            for cmd in ('clear', 'more', 'less', 'man'):
+                self.alias_manager.soft_define_alias(cmd, cmd)
+
         # Flush the private list of module references kept for script
         # execution protection
         self.clear_main_mod_cache()
diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py
--- a/IPython/terminal/interactiveshell.py
+++ b/IPython/terminal/interactiveshell.py
@@ -447,7 +447,7 @@ def init_alias(self):
         # need direct access to the console in a way that we can't emulate in
         # GUI or web frontend
         if os.name == 'posix':
-            for cmd in ['clear', 'more', 'less', 'man']:
+            for cmd in ('clear', 'more', 'less', 'man'):
                 self.alias_manager.soft_define_alias(cmd, cmd)
 
 


Test patch:
diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py
--- a/IPython/core/tests/test_interactiveshell.py
+++ b/IPython/core/tests/test_interactiveshell.py
@@ -495,6 +495,16 @@ def test_last_execution_result(self):
         self.assertFalse(ip.last_execution_result.success)
         self.assertIsInstance(ip.last_execution_result.error_in_exec, NameError)
 
+    def test_reset_aliasing(self):
+        """ Check that standard posix aliases work after %reset. """
+        if os.name != 'posix':
+            return
+
+        ip.reset()
+        for cmd in ('clear', 'more', 'less', 'man'):
+            res = ip.run_cell('%' + cmd)
+            self.assertEqual(res.success, True)
+
 
 class TestSafeExecfileNonAsciiPath(unittest.TestCase):