Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion IPython/extensions/autoreload.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,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:
Expand Down
26 changes: 26 additions & 0 deletions IPython/extensions/tests/test_autoreload.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import sys
import tempfile
import textwrap
import shutil
import random
import time
Expand All @@ -23,6 +24,8 @@
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

Expand Down Expand Up @@ -126,6 +129,29 @@ def new_module(self, code):
#-----------------------------------------------------------------------------

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
Expand Down
1 change: 1 addition & 0 deletions docs/source/whatsnew/pr/autoreload-enum.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* autoreload can now reload ``Enum``. See :ghissue:`10232` and :ghpull:`10316`