Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 157886e

Browse files
authored
Suppressing binary operation lint message (#1319)
* Revert "Adding diagnostic error on binary operations with incompatible types (#1254)" This is due to the fact that current operator type checking is too inaccurate to give diagnostics - operator overloading is a challenge to face for the future This reverts commit 753220f.
1 parent 2b6befa commit 157886e

File tree

6 files changed

+5
-120
lines changed

6 files changed

+5
-120
lines changed

src/Analysis/Ast/Impl/Analyzer/Evaluation/ExpressionEval.Operators.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313
// See the Apache Version 2.0 License for specific language governing
1414
// permissions and limitations under the License.
1515

16-
using Microsoft.Python.Analysis.Diagnostics;
1716
using Microsoft.Python.Analysis.Modules;
1817
using Microsoft.Python.Analysis.Types;
1918
using Microsoft.Python.Analysis.Types.Collections;
2019
using Microsoft.Python.Analysis.Values;
21-
using Microsoft.Python.Core;
2220
using Microsoft.Python.Parsing;
2321
using Microsoft.Python.Parsing.Ast;
24-
using ErrorCodes = Microsoft.Python.Analysis.Diagnostics.ErrorCodes;
2522

2623
namespace Microsoft.Python.Analysis.Analyzer.Evaluation {
2724
internal sealed partial class ExpressionEval {
@@ -124,9 +121,6 @@ private IMember GetValueFromBinaryOp(Expression expr) {
124121

125122
if (leftIsSupported && rightIsSupported) {
126123
if (TryGetValueFromBuiltinBinaryOp(op, leftTypeId, rightTypeId, Interpreter.LanguageVersion.Is3x(), out var member)) {
127-
if (member.IsUnknown()) {
128-
ReportOperatorDiagnostics(expr, leftType, rightType, op);
129-
}
130124
return member;
131125
}
132126
}
@@ -440,14 +434,5 @@ private static (string name, string swappedName) OpMethodName(PythonOperator op)
440434

441435
return (null, null);
442436
}
443-
private void ReportOperatorDiagnostics(Expression expr, IPythonType leftType, IPythonType rightType, PythonOperator op) {
444-
ReportDiagnostics(Module.Uri, new DiagnosticsEntry(
445-
Resources.UnsupporedOperandType.FormatInvariant(op.ToCodeString(), leftType.Name, rightType.Name),
446-
GetLocation(expr).Span,
447-
ErrorCodes.UnsupportedOperandType,
448-
Severity.Error,
449-
DiagnosticSource.Analysis));
450-
}
451-
452437
}
453438
}

src/Analysis/Ast/Impl/Diagnostics/ErrorCodes.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public static class ErrorCodes {
2525
public const string UndefinedVariable = "undefined-variable";
2626
public const string VariableNotDefinedGlobally= "variable-not-defined-globally";
2727
public const string VariableNotDefinedNonLocal = "variable-not-defined-nonlocal";
28-
public const string UnsupportedOperandType = "unsupported-operand-type";
2928
public const string ReturnInInit = "return-in-init";
3029
public const string TypingNewTypeArguments = "typing-newtype-arguments";
3130
public const string TypingGenericArguments = "typing-generic-arguments";

src/Analysis/Ast/Impl/Resources.Designer.cs

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Analysis/Ast/Impl/Resources.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@
192192
<data name="NewTypeFirstArgNotString" xml:space="preserve">
193193
<value>The first argument to NewType must be a string, but it is of type '{0}'.</value>
194194
</data>
195-
<data name="UnsupporedOperandType" xml:space="preserve">
196-
<value>Unsupported operand types for '{0}': '{1}' and '{2}'</value>
197-
</data>
198195
<data name="ReturnInInit" xml:space="preserve">
199196
<value>Explicit return in __init__ </value>
200197
</data>

src/Analysis/Ast/Test/LintNoQATests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,15 @@ public async Task IgnoreNoQAUppercase(string code) {
8181

8282
[TestMethod, Priority(0)]
8383
public async Task VarNamedNoQAStillGivesDiagnostic() {
84-
const string code = @"
85-
noqa = 1 + 'str'
86-
";
84+
string code = GenericSetup + "NOQA = Generic[T, T]";
85+
8786
var analysis = await GetAnalysisAsync(code);
8887
analysis.Diagnostics.Should().HaveCount(1);
8988

9089
var diagnostic = analysis.Diagnostics.ElementAt(0);
91-
diagnostic.ErrorCode.Should().Be(ErrorCodes.UnsupportedOperandType);
92-
diagnostic.Message.Should().Be(Resources.UnsupporedOperandType.FormatInvariant("+", "int", "str"));
93-
diagnostic.SourceSpan.Should().Be(2, 8, 2, 17);
90+
diagnostic.Message.Should().Be(Resources.GenericNotAllUnique);
91+
diagnostic.ErrorCode.Should().Be(ErrorCodes.TypingGenericArguments);
92+
diagnostic.SourceSpan.Should().Be(8, 8, 8, 21);
9493
diagnostic.Severity.Should().Be(Severity.Error);
9594
}
9695

src/Analysis/Ast/Test/LintOperatorTests.cs

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)