Autoreload Enum Error #10232

Closed
alexmarder opened this Issue Feb 1, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@alexmarder

alexmarder commented Feb 1, 2017

I'm getting a weird error when trying to use autoreload and Enums. I have an Enum class defined in a file as:

class MyEnum(Enum):
    A = 'A'
    B = 'B'

Using %autoreload 2, if I try to add C = 'C' to MyEnum, or remove an existing definition, I get the following error:

[autoreload of updates_type failed: Traceback (most recent call last):
  File "/home/amarder/anaconda3/lib/python3.5/site-packages/IPython/extensions/autoreload.py", line 247, in check
    superreload(m, reload, self.old_objects)
RecursionError: maximum recursion depth exceeded
]

Sometimes it is a different error:

[autoreload of updates_type failed: Traceback (most recent call last):
  File "/home/amarder/anaconda3/lib/python3.5/site-packages/IPython/extensions/autoreload.py", line 247, in check
    superreload(m, reload, self.old_objects)
AttributeError: __abstractmethods__
]

I'm running the code on Debian Linux, using Anaconda with python 3.5.

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Feb 1, 2017

Member

autoreload is a bit black magic, so it's not a big surprise when it breaks.

I'd guess that the recursion error is because enum values have a reference back to their class (e.g. MyEnum.A.__objclass__, so there's an infinite chain of attributes that it's trying to replace: MyEnum.A.__objclass__.A.__objclass__.<etc>

Member

takluyver commented Feb 1, 2017

autoreload is a bit black magic, so it's not a big surprise when it breaks.

I'd guess that the recursion error is because enum values have a reference back to their class (e.g. MyEnum.A.__objclass__, so there's an infinite chain of attributes that it's trying to replace: MyEnum.A.__objclass__.A.__objclass__.<etc>

@alexmarder

This comment has been minimized.

Show comment
Hide comment
@alexmarder

alexmarder Feb 1, 2017

If that's true, is there a way to mark a class as having been already reloaded so autoreload does not try again?

If that's true, is there a way to mark a class as having been already reloaded so autoreload does not try again?

@takluyver

This comment has been minimized.

Show comment
Hide comment
@takluyver

takluyver Feb 1, 2017

Member

Not at present. Actually, I now think my guess was wrong; MyEnum.A is not a type, so it should be updated like that. You can see the code updating a class object here:

def update_class(old, new):

Member

takluyver commented Feb 1, 2017

Not at present. Actually, I now think my guess was wrong; MyEnum.A is not a type, so it should be updated like that. You can see the code updating a class object here:

def update_class(old, new):

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Feb 1, 2017

Member

seem like in update_class the two references old_obj and new_obj can be the same (I'm going to guess that's the point of enums, where instances are shared.
So continue if they are the same should be enough.

Member

Carreau commented Feb 1, 2017

seem like in update_class the two references old_obj and new_obj can be the same (I'm going to guess that's the point of enums, where instances are shared.
So continue if they are the same should be enough.

@Carreau

This comment has been minimized.

Show comment
Hide comment
@Carreau

Carreau Feb 1, 2017

Member

also we should bump the number of stacks shown to something like 10-ish (or make it configurable) to be able to debug things like that better.

Member

Carreau commented Feb 1, 2017

also we should bump the number of stacks shown to something like 10-ish (or make it configurable) to be able to debug things like that better.

@Carreau Carreau modified the milestone: 6.0 Feb 2, 2017

Carreau added a commit to Carreau/ipython that referenced this issue Feb 21, 2017

Carreau added a commit to Carreau/ipython that referenced this issue Feb 21, 2017

Carreau added a commit to Carreau/ipython that referenced this issue Feb 22, 2017

@takluyver takluyver closed this in #10316 Feb 22, 2017

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