Barak Adorian
Barak Adorian

Reputation: 223

PyCharm debugger doesn't show objects' content: "Unable to get repr for <type 'list>"

Debugging with PyCharm (happens on multiple versions) I'm unable to correctly view some lists and dictionaries (other are presented correctly). In the view window the object's name is presented with the message: {list} Unable to get repr for <type 'list> or {dict} Unable to get repr for <type 'dict'>

An update: In one of my attempts, I received the following message from the debugger (presented instead of the value of one of the list variable):

Unable to display children:Error resolving variables Traceback (most recent call last): File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 1004, in do_it _typeName, valDict = pydevd_vars.resolve_compound_variable(self.thread_id, self.frame_id, self.scope, self.attributes) TypeError: 'NoneType' object is not iterable

I'll appreciate any idea as for what may cause this behavior?

Thanks!

Upvotes: 13

Views: 8749

Answers (5)

Eduard
Eduard

Reputation: 3671

For me the problem was that __repr__was returning a dict and PyCharm is expecitng a string.

So, I modified the repr method like this:

    def __repr__(self):
      return str({
        'id': self.id,
        'email': self.email,
        'name': self.name
      })

This got rid of the Unable to get repr for... error

Upvotes: 0

DangerMouse
DangerMouse

Reputation: 734

Extending the scope of the problem rather than adding an answer - all the other suggestions are what I do normally to get this working.

Could it be a race condition?

For me it appears to be something weird. In the Variables pane I can see correct representation for theObject, repr(theObject) and even [theObject] but if I set a variable in my code thus a = theObject or b = [theObject] then I get the "Unable to get repr for <class 'list'>" message.

theObject in this case is an instance of a subclassed D lang struct wrapped with autowrap.

Upvotes: 0

LaurentP13
LaurentP13

Reputation: 66

It happened to me sometimes and what caused the behaviour was that some MyClass triggered an exception on its str method.

In such a case, PyCharm debugger only showed

some_object = {MyClass} Unable to get repr for <class 'my_app.models.MyClass'>

So what I did to confirm the origin was to watch repr(some_object) in the Watches section of the debugger. And there it gave me an explicit error message:

{TypeError}%d format: a number is required, not NoneType

Which helped me trace back to the origin.

I appreciate this is not a generic answer, but just a complement to Fabio's.

Upvotes: 3

Barak Adorian
Barak Adorian

Reputation: 223

It turned out the problem is due to usage of rpyc.py: The process I was debugging was called through rpyc and while I was debugging it, the calling process received a timeout on the rpyc connection. I think that this caused variables, passed through rpc to lose integrity so the debugger couldn't present them correctly.

The solution was to downgrade rpyc.py to version 3.3.0 (I was on 3.4.2). My colleague, Nurit Izraelov, correctly suggested the rpyc.py version may be the blame.

Thanks all!

Upvotes: 6

Fabio Zadrozny
Fabio Zadrozny

Reputation: 25362

Probably some custom class of yours has a bad __repr__ or __str__ in it and the debugger is unable to print it.

You can probably use a shell at that point to know which elements are actually inside such a dict or list (and see which object has the faulty __repr__ or __str__).

Upvotes: 2

Related Questions