Guest User

Untitled

a guest
Feb 4th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.62 KB | None | 0 0
  1. static const char* expr_as_type_str(expr_ty e)
  2. {
  3.     switch (e->kind) {
  4.     case Tuple_kind: return "tuple";
  5.     case List_kind:
  6.     case ListComp_kind: return "list";
  7.     case Dict_kind:
  8.     case DictComp_kind: return "dict";
  9.     case Set_kind:
  10.     case SetComp_kind: return "set";
  11.     case GeneratorExp_kind: return "generator";
  12.     case JoinedStr_kind:
  13.     case FormattedValue_kind: return "str";
  14.     case Constant_kind: return e->v.Constant.value->ob_type->tp_name;
  15.     default: return NULL;
  16.     }
  17. }
  18.  
  19. static int
  20. check_caller(struct compiler *c, expr_ty e)
  21. {
  22.     switch (e->kind) {
  23.     case Tuple_kind:
  24.     case List_kind:
  25.     case ListComp_kind:
  26.     case Dict_kind:
  27.     case DictComp_kind:
  28.     case Set_kind:
  29.     case SetComp_kind:
  30.     case GeneratorExp_kind:
  31.     case JoinedStr_kind:
  32.     case FormattedValue_kind:
  33.     case Constant_kind:
  34.         return compiler_warn(c, "'%.200s' object is not callable, "
  35.                             "perhaps missed a comma?",
  36.                             expr_as_type_str(e));    
  37.     default:
  38.         return 1;
  39.     }
  40. }
  41.  
  42. static int
  43. check_subscripter(struct compiler *c, expr_ty e)
  44. {
  45.     PyObject *v;
  46.  
  47.     switch (e->kind) {
  48.     case Constant_kind:
  49.         v = e->v.Constant.value;
  50.         if (!(v == Py_None || v == Py_Ellipsis ||
  51.             PyLong_Check(v) || PyFloat_Check(v) || PyComplex_Check(v) ||
  52.             PyAnySet_Check(v)))
  53.             return 1;
  54.     case Set_kind:
  55.     case SetComp_kind:
  56.     case GeneratorExp_kind:
  57.     case Lambda_kind:
  58.         return compiler_warn(c, "'%.200s' object is not subscriptable, "
  59.                             "perhaps missed a comma?",
  60.                             expr_as_type_str(e));
  61.     default:
  62.         return 1;
  63.     }
  64. }
  65.  
  66. static int
  67. check_index(struct compiler *c, expr_ty e, slice_ty s)
  68. {
  69.     const char *type;
  70.     PyObject *v;
  71.  
  72.     if (s->kind != ExtSlice_kind &&
  73.         !(s->kind == Index_kind && s->v.Index.value->kind == Constant_kind
  74.           && PyTuple_Check(s->v.Index.value->v.Constant.value)))
  75.     {
  76.         return 1;
  77.     }
  78.  
  79.     switch (e->kind) {
  80.     case Constant_kind:
  81.         v = e->v.Constant.value;
  82.         if (!(PyUnicode_Check(v) || PyBytes_Check(v) || PyTuple_Check(v)))
  83.             return 1;
  84.     case Tuple_kind:
  85.     case List_kind:
  86.     case ListComp_kind:
  87.     case JoinedStr_kind:
  88.     case FormattedValue_kind:
  89.         return compiler_warn(c, "%.200s indices must be integers or slices, "
  90.                             "not tuple, "
  91.                             "perhaps missed a comma?",
  92.                             expr_as_type_str(e));
  93.     default:
  94.         return 1;
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment