Skip to content

magic command reset is not working #13087

Open

Description

@dmytroxshevchuk

I found that %reset -f command not working. I see in docs and in namespace.py file instruction how to use reset command and expected result, its looks like:

In [9]: %reset -f
In [1]: 

So I expect that after %reset -f command, number in [9] must be reset and will be [1].
In my case its looks like:

In [35]: %reset -f
In [36]:

So, this number is not reset after magic command. Arguments like --aggressive and -s is not help.

Also in docs I found that must be created new session:

By default (without this option), we do a ‘hard’ reset, giving you a new session and removing all references to objects from the current session.

But I go through the code and found that by default we send new_session = False:

if 's' in opts: # Soft reset
user_ns = self.shell.user_ns
for i in self.who_ls():
del(user_ns[i])
elif len(args) == 0: # Hard reset
self.shell.reset(new_session=False, aggressive=("aggressive" in opts))

How can I restart session, reset [n] value or fully clear caches/modules without restart main application?

Activity

  1. MrMino commented on Aug 31, 2021

    @MrMino
    Member

    Judging by %reset docstring, this is a regression. And, wow, it's an old one.

    • The new_session=False goes back to b24bd65 (10 years back). It's the first commit which breaks the magic.
    • It works on the previous commit, a6a440b.

    I'm not sure what's the context of the b24bd65 change. In any case, I think that given the docstring and the fact that, intuitively, a reset should get the console back to its initial state, I can safely mark this as a bug.

    Currently new_session=True would also have a small quirk, where it resets to [2] instead of [1]. Something to look into if we ever get the True back. In Jupyter Notebook, the cell with %reset gets [1], which leads me to believe that simply, the new session starts before the counter is incremented, and the magic should prevent that somehow.

  2. aliassar commented on Nov 3, 2026

    @aliassar

    Can I work on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions