From 78321701d13658ca71156b98dfed142716be168a Mon Sep 17 00:00:00 2001 From: Victor Milovanov Date: Mon, 24 Sep 2018 18:54:20 -0700 Subject: [PATCH 1/3] added an inheritance test for property type fixed namespace in InheritanceTests --- src/Analysis/Engine/Test/InheritanceTests.cs | 28 ++++++++++++++++++- ...rosoft.Python.Analysis.Engine.Tests.csproj | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Analysis/Engine/Test/InheritanceTests.cs b/src/Analysis/Engine/Test/InheritanceTests.cs index 052b425e0..3eece791e 100644 --- a/src/Analysis/Engine/Test/InheritanceTests.cs +++ b/src/Analysis/Engine/Test/InheritanceTests.cs @@ -3,12 +3,13 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.FluentAssertions; using Microsoft.PythonTools.Interpreter; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; -namespace Microsoft.PythonTools.Analysis { +namespace AnalysisTests { [TestClass] public class InheritanceTests { public TestContext TestContext { get; set; } @@ -38,5 +39,30 @@ def virt(): analysis.Should().HaveVariable("b").OfType(BuiltinTypeId.Int); } } + + [TestMethod] + public async Task AbstractPropertyReturnTypeIgnored() { + var code = @" +import abc + +class A: + @abc.abstractproperty + def virt(): + pass + +class B(A): + @property + def virt(): + return 42 + +a = A() +b = a.virt"; + + using (var server = await new Server().InitializeAsync(PythonVersions.Required_Python36X)) { + var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(code); + + analysis.Should().HaveVariable("b").OfType(BuiltinTypeId.Int); + } + } } } diff --git a/src/Analysis/Engine/Test/Microsoft.Python.Analysis.Engine.Tests.csproj b/src/Analysis/Engine/Test/Microsoft.Python.Analysis.Engine.Tests.csproj index 8353a7386..df62a46ee 100644 --- a/src/Analysis/Engine/Test/Microsoft.Python.Analysis.Engine.Tests.csproj +++ b/src/Analysis/Engine/Test/Microsoft.Python.Analysis.Engine.Tests.csproj @@ -1,7 +1,7 @@  netcoreapp2.1 - Microsoft.PythonTools.Analysis + AnalysisTests Microsoft.Python.Analysis.Engine.Tests From 9eecb281f01aedb2384b1d339ab040d9df9ad5fd Mon Sep 17 00:00:00 2001 From: Victor Milovanov Date: Mon, 24 Sep 2018 18:54:49 -0700 Subject: [PATCH 2/3] fixed processing of @abc's decorators --- .../Engine/Impl/Analyzer/FunctionAnalysisUnit.cs | 3 ++- src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs b/src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs index f2a7e9db7..15891762f 100644 --- a/src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs +++ b/src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs @@ -101,7 +101,8 @@ private bool ProcessAbstractDecorators(IAnalysisSet decorator) { // Only handle these if they are specialized foreach (var d in decorator.OfType()) { - if (d.DeclaringModule?.ModuleName != "abc") { + if (d.DeclaringModule != null + && d.DeclaringModule.ModuleName != "abc") { continue; } diff --git a/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs b/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs index ed9cc1228..e1e1b889e 100644 --- a/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs +++ b/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs @@ -217,6 +217,15 @@ public override IEnumerable Locations { } } + public override string Name { + get { + if (_original == null) + return base.Name; + + return _original.Name; + } + } + public override IEnumerable Overloads { get { if (_original == null) { From 5fc865299b24be29a82219c193790175bdf64700 Mon Sep 17 00:00:00 2001 From: Victor Milovanov Date: Tue, 25 Sep 2018 11:23:29 -0700 Subject: [PATCH 3/3] use C# 7 syntax when possible --- src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs b/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs index e1e1b889e..486f051c9 100644 --- a/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs +++ b/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs @@ -217,14 +217,7 @@ public override IEnumerable Locations { } } - public override string Name { - get { - if (_original == null) - return base.Name; - - return _original.Name; - } - } + public override string Name => _original == null ? base.Name : this._original.Name; public override IEnumerable Overloads { get {