(cls, prop: Property)
| 1101 | |
| 1102 | @classmethod |
| 1103 | def make_attribute(cls, prop: Property) -> cst.Call: |
| 1104 | func_name = None |
| 1105 | attr = cst.Subscript( |
| 1106 | value=cst.Name("attributes"), |
| 1107 | slice=[cst.SubscriptElement(slice=cst.Index(cst.SimpleString(f'"{prop.name}"')))], |
| 1108 | ) |
| 1109 | if prop.data_type is None: |
| 1110 | func_name = "_makeClassAttribute" |
| 1111 | args = [cst.Arg(cst.Name("None")), cst.Arg(attr)] |
| 1112 | # TODO: warn about unknown / supported type |
| 1113 | elif isinstance(prop.data_type, GithubClass): |
| 1114 | func_name = "_makeClassAttribute" |
| 1115 | args = [cst.Arg(cls.create_type(prop.data_type)), cst.Arg(attr)] |
| 1116 | elif prop.data_type.type == "bool": |
| 1117 | func_name = "_makeBoolAttribute" |
| 1118 | args = [cst.Arg(attr)] |
| 1119 | elif prop.data_type.type == "int": |
| 1120 | func_name = "_makeIntAttribute" |
| 1121 | args = [cst.Arg(attr)] |
| 1122 | elif prop.data_type.type == "float": |
| 1123 | func_name = "_makeFloatAttribute" |
| 1124 | args = [cst.Arg(attr)] |
| 1125 | elif prop.data_type.type == "datetime": |
| 1126 | func_name = "_makeDatetimeAttribute" |
| 1127 | args = [cst.Arg(attr)] |
| 1128 | elif prop.data_type.type == "str": |
| 1129 | func_name = "_makeStringAttribute" |
| 1130 | args = [cst.Arg(attr)] |
| 1131 | elif prop.data_type.type == "dict": |
| 1132 | if isinstance(prop.data_type.inner_types[1], GithubClass): |
| 1133 | func_name = "_makeDictOfStringsToClassesAttribute" |
| 1134 | args = [cst.Arg(cls.create_type(prop.data_type.inner_types[1])), cst.Arg(attr)] |
| 1135 | else: |
| 1136 | func_name = "_makeDictAttribute" |
| 1137 | args = [cst.Arg(attr)] |
| 1138 | elif prop.data_type.type == "list": |
| 1139 | if prop.data_type.inner_types[0] is None: |
| 1140 | func_name = "_makeListOfClassesAttribute" |
| 1141 | args = [cst.Arg(attr)] |
| 1142 | # TODO: warn about unknown / supported type |
| 1143 | elif isinstance(prop.data_type.inner_types[0], GithubClass): |
| 1144 | func_name = "_makeListOfClassesAttribute" |
| 1145 | args = [cst.Arg(cls.create_type(prop.data_type.inner_types[0])), cst.Arg(attr)] |
| 1146 | # TODO: warn about unknown / supported type |
| 1147 | elif prop.data_type.inner_types[0].type == "int": |
| 1148 | func_name = "_makeListOfIntsAttribute" |
| 1149 | args = [cst.Arg(attr)] |
| 1150 | elif prop.data_type.inner_types[0].type == "str": |
| 1151 | func_name = "_makeListOfStringsAttribute" |
| 1152 | args = [cst.Arg(attr)] |
| 1153 | elif prop.data_type.inner_types[0].type == "dict": |
| 1154 | func_name = "_makeListOfDictsAttribute" |
| 1155 | args = [cst.Arg(attr)] |
| 1156 | elif ( |
| 1157 | prop.data_type.inner_types[0].type == "list" |
| 1158 | and prop.data_type.inner_types[0].inner_types[0].type == "str" |
| 1159 | ): |
| 1160 | func_name = "_makeListOfListOfStringsAttribute" |
no test coverage detected