All per-Op state we would like to precompute/validate.
| 230 | |
| 231 | |
| 232 | class _OpInfo(object): |
| 233 | """All per-Op state we would like to precompute/validate.""" |
| 234 | |
| 235 | def __init__(self, op_def): |
| 236 | self.op_def = op_def |
| 237 | # TODO(josh11b): SWIG the ValidateOpDef() function from C++ and call it |
| 238 | # here, instead of these checks. |
| 239 | for arg in list(op_def.input_arg) + list(op_def.output_arg): |
| 240 | num_type_fields = _NumTypeFields(arg) |
| 241 | if num_type_fields != 1: |
| 242 | raise TypeError("Arg '%s' of '%s' must have one type field not %d" % |
| 243 | (arg.name, op_def.name, num_type_fields)) |
| 244 | if arg.type_attr: |
| 245 | attr_type = _Attr(op_def, arg.type_attr).type |
| 246 | if attr_type != "type": |
| 247 | raise TypeError("Attr '%s' of '%s' used as a type_attr " |
| 248 | "but has type %s" % |
| 249 | (arg.type_attr, op_def.name, attr_type)) |
| 250 | if arg.type_list_attr: |
| 251 | attr_type = _Attr(op_def, arg.type_list_attr).type |
| 252 | if attr_type != "list(type)": |
| 253 | raise TypeError( |
| 254 | "Attr '%s' of '%s' used as a type_list_attr but has type %s" % |
| 255 | (arg.type_attr, op_def.name, attr_type)) |
| 256 | if arg.number_attr: |
| 257 | attr_type = _Attr(op_def, arg.number_attr).type |
| 258 | if attr_type != "int": |
| 259 | raise TypeError( |
| 260 | "Attr '%s' of '%s' used as a number_attr but has type %s" % |
| 261 | (arg.number_attr, op_def.name, attr_type)) |
| 262 | |
| 263 | |
| 264 | # pylint: disable=g-doc-return-or-yield |