Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static const char* expr_as_type_str(expr_ty e)
- {
- switch (e->kind) {
- case Tuple_kind: return "tuple";
- case List_kind:
- case ListComp_kind: return "list";
- case Dict_kind:
- case DictComp_kind: return "dict";
- case Set_kind:
- case SetComp_kind: return "set";
- case GeneratorExp_kind: return "generator";
- case JoinedStr_kind:
- case FormattedValue_kind: return "str";
- case Constant_kind: return e->v.Constant.value->ob_type->tp_name;
- default: return NULL;
- }
- }
- static int
- check_caller(struct compiler *c, expr_ty e)
- {
- switch (e->kind) {
- case Tuple_kind:
- case List_kind:
- case ListComp_kind:
- case Dict_kind:
- case DictComp_kind:
- case Set_kind:
- case SetComp_kind:
- case GeneratorExp_kind:
- case JoinedStr_kind:
- case FormattedValue_kind:
- case Constant_kind:
- return compiler_warn(c, "'%.200s' object is not callable, "
- "perhaps missed a comma?",
- expr_as_type_str(e));
- default:
- return 1;
- }
- }
- static int
- check_subscripter(struct compiler *c, expr_ty e)
- {
- PyObject *v;
- switch (e->kind) {
- case Constant_kind:
- v = e->v.Constant.value;
- if (!(v == Py_None || v == Py_Ellipsis ||
- PyLong_Check(v) || PyFloat_Check(v) || PyComplex_Check(v) ||
- PyAnySet_Check(v)))
- return 1;
- case Set_kind:
- case SetComp_kind:
- case GeneratorExp_kind:
- case Lambda_kind:
- return compiler_warn(c, "'%.200s' object is not subscriptable, "
- "perhaps missed a comma?",
- expr_as_type_str(e));
- default:
- return 1;
- }
- }
- static int
- check_index(struct compiler *c, expr_ty e, slice_ty s)
- {
- const char *type;
- PyObject *v;
- if (s->kind != ExtSlice_kind &&
- !(s->kind == Index_kind && s->v.Index.value->kind == Constant_kind
- && PyTuple_Check(s->v.Index.value->v.Constant.value)))
- {
- return 1;
- }
- switch (e->kind) {
- case Constant_kind:
- v = e->v.Constant.value;
- if (!(PyUnicode_Check(v) || PyBytes_Check(v) || PyTuple_Check(v)))
- return 1;
- case Tuple_kind:
- case List_kind:
- case ListComp_kind:
- case JoinedStr_kind:
- case FormattedValue_kind:
- return compiler_warn(c, "%.200s indices must be integers or slices, "
- "not tuple, "
- "perhaps missed a comma?",
- expr_as_type_str(e));
- default:
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment