From cd68559b0861ad2be12be29b9d4b7ec66e885191 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Thu, 10 May 2012 17:57:50 +0200 Subject: [PATCH] Separate asserts on type and assignments of values of attributes --- CodeGenerator/templates/GithubObject.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CodeGenerator/templates/GithubObject.py b/CodeGenerator/templates/GithubObject.py index 2b10f68e..741e24b7 100644 --- a/CodeGenerator/templates/GithubObject.py +++ b/CodeGenerator/templates/GithubObject.py @@ -83,15 +83,24 @@ class {{ class.name }}( object ): {% if attribute.type.name == "bool" %} assert isinstance( attributes[ "{{ attribute.name }}" ], bool ) {% endif %} - self.__{{ attribute.name }} = attributes[ "{{ attribute.name }}" ] {% else %} assert isinstance( attributes[ "{{ attribute.name }}" ], dict ) - self.__{{ attribute.name }} = {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self.__requester, attributes[ "{{ attribute.name }}" ], lazy = True ) {% endif %} {% endif %} {% if attribute.type.cardinality == "list" %} assert isinstance( attributes[ "{{ attribute.name }}" ], list ) and ( len( attributes[ "{{ attribute.name }}" ] ) == 0 or isinstance( attributes[ "{{ attribute.name }}" ][ 0 ], dict ) ) +{% endif %} + +{% if attribute.type.cardinality == "scalar" %} +{% if attribute.type.simple %} + self.__{{ attribute.name }} = attributes[ "{{ attribute.name }}" ] +{% else %} + self.__{{ attribute.name }} = {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self.__requester, attributes[ "{{ attribute.name }}" ], lazy = True ) +{% endif %} +{% endif %} + +{% if attribute.type.cardinality == "list" %} self.__{{ attribute.name }} = [ {% if attribute.type.name != class.name %}{{ attribute.type.name }}.{% endif %}{{ attribute.type.name }}( self.__requester, element, lazy = True ) for element in attributes[ "{{ attribute.name }}" ]