Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoreload Enum Error #10232

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

Autoreload Enum Error #10232

alexmarder opened this issue Feb 1, 2017 · 5 comments
Milestone

Comments

@alexmarder
Copy link

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
Copy link
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>

@alexmarder
Copy link
Author

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

@takluyver
Copy link
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):

@Carreau
Copy link
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
Copy link
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants