@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());
          }
        }
      }
    }
Ejemplo n.º 2
0
 @Override
 public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
   for (PyTypeProvider provider : Extensions.getExtensions(PyTypeProvider.EP_NAME)) {
     final PyType type = provider.getCallableType(this, context);
     if (type != null) {
       return type;
     }
   }
   final boolean hasCustomDecorators =
       PyUtil.hasCustomDecorators(this)
           && !PyUtil.isDecoratedAsAbstract(this)
           && getProperty() == null;
   final PyFunctionType type = new PyFunctionType(this);
   if (hasCustomDecorators) {
     return PyUnionType.createWeakType(type);
   }
   return type;
 }
 public static void inspectPyArgumentList(
     PyArgumentList node,
     ProblemsHolder holder,
     final TypeEvalContext context,
     int implicitOffset) {
   if (node.getParent() instanceof PyClass) return; // class Foo(object) is also an arg list
   CallArgumentsMapping result =
       node.analyzeCall(
           PyResolveContext.noImplicits().withTypeEvalContext(context), implicitOffset);
   final PyCallExpression.PyMarkedCallee callee = result.getMarkedCallee();
   if (callee != null) {
     final Callable callable = callee.getCallable();
     // Decorate functions may have different parameter lists. We don't match arguments with
     // parameters of decorators yet
     if (callable instanceof PyFunction && PyUtil.hasCustomDecorators((PyFunction) callable)) {
       return;
     }
   }
   highlightIncorrectArguments(holder, result, context);
   highlightMissingArguments(node, holder, result);
   highlightStarArgumentTypeMismatch(node, holder, context);
 }