r/kivy • • Oct 06 '17

Same exact code, suddenly doesn't work... Value error coming from one of the kivy files.

Here is the kivy part of the error, which are the last lines:

   File "kivy/_event.pyx", line 199, in 
kivy._event.EventDispatcher.__cinit__ (kivy/_event.c:4455)
   File "kivy/properties.pyx", line 910, in 
kivy.properties.DictProperty.link (kivy/properties.c:14623)
   File "kivy/properties.pyx", line 827, in 
kivy.properties.ObservableDict.__init__ 
(kivy/properties.c:12192)
 ValueError: dictionary update sequence element #0 has length 6; 2 is required

I could swear I have not touched a line of this code in weeks, as I have been working on some other code. The part of my code that activated this error is loading an NPC class that loads a bunch of images and properties, among them several dictionaries. But I swear it all worked, has anyone else had this issue?

1 Upvotes

15 comments sorted by

2

u/[deleted] Oct 07 '17

Hard to say without more details.. it could be some coupling you don't realise of course..

Best general suggestion i have is use git bisect to figure out what broke it..

1

u/Exodus111 Oct 07 '17

Well, I tried to go back to the last save in github, and I had the same issue, which is impossible, because I know it worked when I saved to github then.

Its so strange, because the entity classes (player/npc) is one of the first things I did, I havent touched that code in months.

I think the first thing I wanna do is look at the actual kivy code that is causing the issue, and try to trace my way from there. But I cant find that file, its supposed to be properties.pyx in the kivy folder, but that folder has no such file. Am I reading this wrong?

3

u/[deleted] Oct 07 '17

The file is in the repository - https://github.com/kivy/kivy/tree/master/kivy

2

u/Exodus111 Oct 07 '17

Thanks, same folder as app.py, but not on my machine. Does Ubuntu store some files somewhere else or is there something I dont know.

2

u/[deleted] Oct 07 '17

I guess they distribute only the compiled file or something? Not sure, i usually build from source

2

u/Exodus111 Oct 07 '17

I have the other files, I have the properties.pxd file, just not that one. Not sure if I have all the others, I'd have to take a look.

I think it might be prudent to try a virtual environment and try from there.

2

u/Exodus111 Oct 07 '17

Hmm, here is the piece of code in question, the offending line is the last one, the call to super():

class ObservableDict(dict):
    # Internal class to observe changes inside a native python dict.
    def __init__(self, *largs):
        self.prop = largs[0]
        self.obj = largs[1]
        super(ObservableDict, self).__init__(*largs[2:])

Which makes sense, since the error is a Python error, not a Kivy one. So when calling the Python Dict this class inherits from, we are essentially doing a dict update, with something that is supposed to be 2 elements. A key and a Value, because its a Dict. Instead of that, the list '*largs[2:]' is unpacking something with 6 values. Which seems impossible, since the slice should ensure only 2 items.

So, what is most likely happening is that the first of those two values, meant for the Key of the dictionary entry, is a List or a Tuple containing more then one entry, which doesn't work for a Key. I think I'm right about that, but I wont really be able to look at this until Monday.

At least I have some idea of what is going on, thanks for the help.

2

u/[deleted] Oct 09 '17

since the slice should ensure only 2 items.

It does not do that -- it ensures that the two first items are skipped. The error is caused by some data that does not conform to expectations:

>>> d = {}
>>> d.update([[1,2,3,4,5,6]])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: dictionary update sequence element #0 has length 6; 2 is required

1

u/Exodus111 Oct 09 '17

Ok, I'm reading the slice wrong. That makes more sense then. Thanks for pointing it out, I knew it was a good idea to take it step by step, you never know where the mistaken assumption may lie.

2

u/[deleted] Oct 09 '17

To be clear the update expects a list of key, value tuples as you say:

>>> d.update([['a', 1], ['b', 2]])
>>> d
{'a': 1, 'b': 2}

Exactly what causes this I don't know. But it's very likely "something" in your code..

1

u/Exodus111 Oct 09 '17

Ok I found it. A Kivy DictProperty was incorrectly set up in a class the offending class was inheriting from.

Seems like I deleted some characters by mistake or something.

Thanks for the help.

2

u/[deleted] Oct 10 '17

Ahh okay -- what was the problem exactly, if you don't mind? Good info to have in the back pocket when the next guy shows up with the same error :)

3

u/Exodus111 Oct 10 '17

Something like this: (Can't show real code)

class Entity(Widget):
    poses = DictProperty({"right", "left"})  # <--Whole section of that missing for some reason.

So it was a typo, as I said, something got deleted somehow.
It should not have been a big deal to find, but the issue was that it never pointed to that line, instead it pointed to this (as an example):

npc1 = NPC()

So NPC, inherits from Entity. But it was far fetched for me to assume one of the properties of Entity was at fault. (Entity has like 30 properties)

I though since it was happening on instantiation something was wrong in the .kv file.

Anyway, its a problem I probably would have picked up with a smaller code base, but since the game is not far off from release, the codebase is getting somewhat unwieldy. :-P

2

u/[deleted] Oct 10 '17

Ahh okay thanks! From the original description I suspected something like

class A:
    p = DictProperty()

class B(A):
    p = ListProperty([1,2,3,4,5,6])

I always suspected those kinds of collisions have some interesting side effects.. ;)

1

u/Exodus111 Oct 10 '17

Yeah, that could do it as well I guess. :-P