@Override
    public void visitPyAssignmentStatement(PyAssignmentStatement node) {
      final PyExpression value = node.getAssignedValue();
      if (value instanceof PyCallExpression) {
        final PyType type = myTypeEvalContext.getType(value);
        final PyExpression callee = ((PyCallExpression) value).getCallee();

        if (type instanceof PyNoneType && callee != null) {
          final PyTypeChecker.AnalyzeCallResults analyzeCallResults =
              PyTypeChecker.analyzeCall(((PyCallExpression) value), myTypeEvalContext);
          if (analyzeCallResults != null) {
            final PyCallable callable = analyzeCallResults.getCallable();
            if (PySdkUtil.isElementInSkeletons(callable)) {
              return;
            }
            if (callable instanceof PyFunction) {
              final PyFunction function = (PyFunction) callable;
              // Currently we don't infer types returned by decorators
              if (hasInheritors(function) || PyUtil.hasCustomDecorators(function)) {
                return;
              }
            }
            registerProblem(
                node,
                PyBundle.message("INSP.none.function.assignment", callee.getName()),
                new PyRemoveAssignmentQuickFix());
          }
        }
      }
    }
コード例 #2
0
 public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
   if (isOperator("and") || isOperator("or")) {
     final PyExpression left = getLeftExpression();
     final PyType leftType = left != null ? context.getType(left) : null;
     final PyExpression right = getRightExpression();
     final PyType rightType = right != null ? context.getType(right) : null;
     if (leftType == null && rightType == null) {
       return null;
     }
     return PyUnionType.union(leftType, rightType);
   }
   final PyTypeChecker.AnalyzeCallResults results = PyTypeChecker.analyzeCall(this, context);
   if (results != null) {
     final PyType type = results.getCallable().getCallType(context, this);
     if (!PyTypeChecker.isUnknown(type) && !(type instanceof PyNoneType)) {
       return type;
     }
   }
   if (PyNames.COMPARISON_OPERATORS.contains(getReferencedName())) {
     return PyBuiltinCache.getInstance(this).getBoolType();
   }
   return null;
 }