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

Fix None being reported as not defined in type hints #336

Merged
merged 1 commit into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public IAnalysisSet LookupAnalysisSetByName(Node node, string name, bool addRef
res = refs.Types;
} else {
// ... warn the user
warn = true;
warn = !(node is ConstantExpression); // Don't warn when None.
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/Analysis/Engine/Test/LanguageServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,27 @@ public async Task DiagnosticsSettingChange() {
}
}

[TestMethod, Priority(0)]
public async Task TypeHintNoneDiagnostic() {
if (this is LanguageServerTests_V2) {
// No type hints in Python 2.
return;
}

var code = @"
def f(b: None) -> None:
b: None
";

var diags = new Dictionary<Uri, PublishDiagnosticsEventArgs>();
using (var s = await CreateServer((Uri)null, null, diags)) {
var u = await s.OpenDefaultDocumentAndGetUriAsync(code);

await s.WaitForCompleteAnalysisAsync(CancellationToken.None);
GetDiagnostics(diags, u).Should().BeEmpty();
}
}

[TestMethod, Priority(0)]
public async Task OnTypeFormattingLine() {
using (var s = await CreateServer()) {
Expand Down