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

Commit 22944ac

Browse files
author
Mikhail Arkhipov
authored
Merge pull request #131 from losttech/losttech/WorkItems/4715
A test to ensure @abc.abstractproperty return value is analyzed correctly
2 parents 7c9de6c + 5fc8652 commit 22944ac

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ private bool ProcessAbstractDecorators(IAnalysisSet decorator) {
101101

102102
// Only handle these if they are specialized
103103
foreach (var d in decorator.OfType<SpecializedCallable>()) {
104-
if (d.DeclaringModule?.ModuleName != "abc") {
104+
if (d.DeclaringModule != null
105+
&& d.DeclaringModule.ModuleName != "abc") {
105106
continue;
106107
}
107108

src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ public override IEnumerable<ILocationInfo> Locations {
217217
}
218218
}
219219

220+
public override string Name => _original == null ? base.Name : this._original.Name;
221+
220222
public override IEnumerable<OverloadResult> Overloads {
221223
get {
222224
if (_original == null) {

src/Analysis/Engine/Test/InheritanceTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
using System.Text;
44
using System.Threading.Tasks;
55
using Microsoft.Python.LanguageServer.Implementation;
6+
using Microsoft.PythonTools.Analysis;
67
using Microsoft.PythonTools.Analysis.FluentAssertions;
78
using Microsoft.PythonTools.Interpreter;
89
using Microsoft.VisualStudio.TestTools.UnitTesting;
910
using TestUtilities;
1011

11-
namespace Microsoft.PythonTools.Analysis {
12+
namespace AnalysisTests {
1213
[TestClass]
1314
public class InheritanceTests {
1415
public TestContext TestContext { get; set; }
@@ -38,5 +39,30 @@ def virt():
3839
analysis.Should().HaveVariable("b").OfType(BuiltinTypeId.Int);
3940
}
4041
}
42+
43+
[TestMethod]
44+
public async Task AbstractPropertyReturnTypeIgnored() {
45+
var code = @"
46+
import abc
47+
48+
class A:
49+
@abc.abstractproperty
50+
def virt():
51+
pass
52+
53+
class B(A):
54+
@property
55+
def virt():
56+
return 42
57+
58+
a = A()
59+
b = a.virt";
60+
61+
using (var server = await new Server().InitializeAsync(PythonVersions.Required_Python36X)) {
62+
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(code);
63+
64+
analysis.Should().HaveVariable("b").OfType(BuiltinTypeId.Int);
65+
}
66+
}
4167
}
4268
}

src/Analysis/Engine/Test/Microsoft.Python.Analysis.Engine.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<TargetFramework>netcoreapp2.1</TargetFramework>
4-
<RootNamespace>Microsoft.PythonTools.Analysis</RootNamespace>
4+
<RootNamespace>AnalysisTests</RootNamespace>
55
<AssemblyName>Microsoft.Python.Analysis.Engine.Tests</AssemblyName>
66
</PropertyGroup>
77
<PropertyGroup>

0 commit comments

Comments
 (0)