Thanks to visit codestin.com
Credit goes to github.com

Skip to content

autoreload explicit+complete missing (but works well) #15019

@jdtsmith

Description

@jdtsmith

The current options for autoreload are encoded as:

        if mode == "" or mode == "now":
            self._reloader.check(True)
        elif mode == "0" or mode == "off":
            self._reloader.enabled = False
        elif mode == "1" or mode == "explicit":
            self._reloader.enabled = True
            self._reloader.check_all = False
            self._reloader.autoload_obj = False
        elif mode == "2" or mode == "all":
            self._reloader.enabled = True
            self._reloader.check_all = True
            self._reloader.autoload_obj = False
        elif mode == "3" or mode == "complete":
            self._reloader.enabled = True
            self._reloader.check_all = True
            self._reloader.autoload_obj = True
        else:
            raise ValueError(f'Unrecognized autoreload mode "{mode}".')

Unfortunately, there is no option for check_all = False + autoload_obj = True. It does not appear this is a necessary limitation. In fact, people might like very much this setting to:

  1. Specify explicitly the modules for autoreload to pay attention to (for speed).
  2. Track the objects in those modules to keep the import from's up to date (for correctness).

I verified this combination works just fine, with some simple testing of files:

%load_ext autoreload
%autoreload -p 3  # aka check_all=True autoload_obj=True
ip=get_ipython()
ip.magics_manager.magics['line']['autoreload'].__self__._reloader.check_all = False
%aimport a, b

Ideally we'd have something like:

check_all autoload_obj Value Description
False False 1 explicit
True False 2 all
False True 3 careful
True True 4 complete

but given that 3 has already been encoded as complete, perhaps 3 and 4 could be swapped, or careful could be 5. Either of these makes it sound like careful is "better than" complete, but it's not really.

The other option would be to support flags to the magic command to toggle these options, instead of/in addition to the names/numbers. So --import_objects and --check_all. Then there would be name+number for only 3 of 4 possible combinations , but you could reach the fourth state like:

[1] %autoreload --import_objects

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions