diff --git a/IPython/extensions/autoreload.py b/IPython/extensions/autoreload.py index 15372af..2fe9974 100644 --- a/IPython/extensions/autoreload.py +++ b/IPython/extensions/autoreload.py @@ -274,9 +274,10 @@ def update_class(old, new): method code objects""" for key in list(old.__dict__.keys()): old_obj = getattr(old, key) - try: new_obj = getattr(new, key) + if old_obj == new_obj: + continue except AttributeError: # obsolete attribute: remove it try: diff --git a/IPython/extensions/tests/test_autoreload.py b/IPython/extensions/tests/test_autoreload.py index 9dc18f2..89c288b 100644 --- a/IPython/extensions/tests/test_autoreload.py +++ b/IPython/extensions/tests/test_autoreload.py @@ -15,6 +15,7 @@ import os import sys import tempfile +import textwrap import shutil import random import time @@ -23,6 +24,8 @@ from io import StringIO import nose.tools as nt import IPython.testing.tools as tt +from IPython.testing.decorators import skipif + from IPython.extensions.autoreload import AutoreloadMagics from IPython.core.events import EventManager, pre_run_cell @@ -126,6 +129,29 @@ class Fixture(object): #----------------------------------------------------------------------------- class TestAutoreload(Fixture): + + @skipif(sys.version_info < (3, 6)) + def test_reload_enums(self): + import enum + mod_name, mod_fn = self.new_module(textwrap.dedent(""" + from enum import Enum + class MyEnum(Enum): + A = 'A' + B = 'B' + """)) + self.shell.magic_autoreload("2") + self.shell.magic_aimport(mod_name) + self.write_file(mod_fn, textwrap.dedent(""" + from enum import Enum + class MyEnum(Enum): + A = 'A' + B = 'B' + C = 'C' + """)) + with tt.AssertNotPrints(('[autoreload of %s failed:' % mod_name), channel='stderr'): + self.shell.run_code("pass") # trigger another reload + + def _check_smoketest(self, use_aimport=True): """ Functional test for the automatic reloader using either diff --git a/docs/source/whatsnew/pr/autoreload-enum.rst b/docs/source/whatsnew/pr/autoreload-enum.rst new file mode 100644 index 0000000..a5103ae --- /dev/null +++ b/docs/source/whatsnew/pr/autoreload-enum.rst @@ -0,0 +1 @@ +* autoreload can now reload ``Enum``. See :ghissue:`10232` and :ghpull:`10316`