Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit cd18568

Browse files
authored
Fix None being reported as not defined in type hints (microsoft#336)
1 parent 82568b2 commit cd18568

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public IAnalysisSet LookupAnalysisSetByName(Node node, string name, bool addRef
150150
res = refs.Types;
151151
} else {
152152
// ... warn the user
153-
warn = true;
153+
warn = !(node is ConstantExpression); // Don't warn when None.
154154
}
155155
}
156156
}

src/Analysis/Engine/Test/LanguageServerTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,27 @@ public async Task DiagnosticsSettingChange() {
363363
}
364364
}
365365

366+
[TestMethod, Priority(0)]
367+
public async Task TypeHintNoneDiagnostic() {
368+
if (this is LanguageServerTests_V2) {
369+
// No type hints in Python 2.
370+
return;
371+
}
372+
373+
var code = @"
374+
def f(b: None) -> None:
375+
b: None
376+
";
377+
378+
var diags = new Dictionary<Uri, PublishDiagnosticsEventArgs>();
379+
using (var s = await CreateServer((Uri)null, null, diags)) {
380+
var u = await s.OpenDefaultDocumentAndGetUriAsync(code);
381+
382+
await s.WaitForCompleteAnalysisAsync(CancellationToken.None);
383+
GetDiagnostics(diags, u).Should().BeEmpty();
384+
}
385+
}
386+
366387
[TestMethod, Priority(0)]
367388
public async Task OnTypeFormattingLine() {
368389
using (var s = await CreateServer()) {

0 commit comments

Comments
 (0)