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

In IPython, DjangoChoices.labels raises AttributeError for 'keys' #33

Closed
ffigiel opened this issue May 17, 2016 · 3 comments
Closed

In IPython, DjangoChoices.labels raises AttributeError for 'keys' #33

ffigiel opened this issue May 17, 2016 · 3 comments

Comments

@ffigiel
Copy link

ffigiel commented May 17, 2016

Hi, I noticed this behavior in ipython. Here's my environment:

Python 3.4.3

Django==1.9.6
django-choices==1.4.2
ipython==4.2.0

And the traceback:

In [20]: class C(DjangoChoices):
    a = ChoiceItem('a', 'A')
    b = ChoiceItem('b', 'B')
    c = ChoiceItem('c', 'C')
   ....:     

In [21]: C.labels
Out[21]: AttributeError
Traceback (most recent call last)
python3.4/site-packages/IPython/core/formatters.py in __call__(self, obj)
    697                 type_pprinters=self.type_printers,
    698                 deferred_pprinters=self.deferred_printers)
--> 699             printer.pretty(obj)
    700             printer.flush()
    701             return stream.getvalue()

python3.4/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    366                 if cls in self.type_pprinters:
    367                     # printer registered in self.type_pprinters
--> 368                     return self.type_pprinters[cls](obj, self, cycle)
    369                 else:
    370                     # deferred printer

python3.4/site-packages/IPython/lib/pretty.py in inner(obj, p, cycle)
    607             return p.text('{...}')
    608         p.begin_group(1, start)
--> 609         keys = obj.keys()
    610         # if dict isn't large enough to be truncated, sort keys before displaying
    611         if not (p.max_seq_length and len(obj) >= p.max_seq_length):

python3.4/site-packages/djchoices/choices.py in __getattribute__(self, name)
     17             return result
     18         else:
---> 19             raise AttributeError("Label for field %s was not found." % name)
     20 
     21     def __setattr__(self, name, value):

AttributeError: Label for field keys was not found.
@ffigiel
Copy link
Author

ffigiel commented May 17, 2016

The same code runs okay in a python script so it's not an urgent bug, however DjangoChoices probably tries to be too smart/hacky?

@sergei-maertens
Copy link
Collaborator

Interesting, it seems like the metaclass is not running properly. I'll see if I can investigate in a few hours. For completeness sake - does this also happen on a regular python shell and/or bpython?

@ffigiel
Copy link
Author

ffigiel commented May 17, 2016

C.labels Works in regular shell as well as python script

sergei-maertens added a commit to sergei-maertens/django-choices that referenced this issue Aug 28, 2016
sergei-maertens added a commit that referenced this issue Aug 28, 2016
Fixed #33: access dict methods of Labels (IPython support)
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

2 participants