Dictionary type-defintion does not support list

Bug #987798 reported by Pezard
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ladon
In Progress
Low
jsgaarde

Bug Description

Hi,

I'm using Ladon 0.7 and as far as I am correct, the dictionary type-defintion does not support lists as type, ie:

class MyType(LadonType):
    attrib = {'type': [PORTABLE_STRING]}

raises an exception (AttributeError: 'list' object has no attribute '__bases__') but

class MyType(LadonType):
    attrib = [PORTABLE_STRING]

does not.

I had a look at the code and I suppose this is due to the fact that, in the method analyze_class of TypeManager in ladon/types/typemanager.py when type(attr_val) == dict (between line 71 and 112) the value of type is not taken into account.

As a very quick hack, on my local version, I added at the end of the condition (between line 112 and 114):
[line 112: attr_val = temp_attr_val *** Not Changed ***]

                 if type(attr_val)==list:
                    if len(attr_val)==1:
                        attr_val = attr_val[0]
                        array_attr = True
                        self.has_lists = True
                    else:
                        raise NeedToDefineParseTimeException("class attributes on LadonTypes must be defined as types, lists.\nclass: %s\nattr: %s" % (cls.__name__,attr))

[line 114: elif type(attr_val)!=type: *** Not Changed ***]

It seems to solve the problem but this is certainly not the more elegant solution for this.

Revision history for this message
jsgaarde (jakob-simon-gaarde) wrote :

This is not a bug, it has simply not been implemented yet, but it is in my to-do list.

Best regards
Jakob Simon-Gaarde

Changed in ladon:
status: New → In Progress
importance: Undecided → Low
assignee: nobody → jsgaarde (jakob-simon-gaarde)
Revision history for this message
Mateusz Mikołajczyk (mikolajczyk-mateusz) wrote :

It certainly works OK on version 0.7.8. I'm attaching a slightly modified version of the above patch that doesn't require code duplication.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.