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

A test to ensure @abc.abstractproperty return value is analyzed correctly #131

Merged
merged 3 commits into from
Sep 26, 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
3 changes: 2 additions & 1 deletion src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ private bool ProcessAbstractDecorators(IAnalysisSet decorator) {

// Only handle these if they are specialized
foreach (var d in decorator.OfType<SpecializedCallable>()) {
if (d.DeclaringModule?.ModuleName != "abc") {
if (d.DeclaringModule != null
&& d.DeclaringModule.ModuleName != "abc") {
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public override IEnumerable<ILocationInfo> Locations {
}
}

public override string Name => _original == null ? base.Name : this._original.Name;

public override IEnumerable<OverloadResult> Overloads {
get {
if (_original == null) {
Expand Down
28 changes: 27 additions & 1 deletion src/Analysis/Engine/Test/InheritanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>Microsoft.PythonTools.Analysis</RootNamespace>
<RootNamespace>AnalysisTests</RootNamespace>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not change namespaces for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only affects what namespace VS uses when you create a new file. It was set to AnalysisTests in PTVS but, I guess, was overlooked when porting, which in turn accidentally caused my new file InheritanceTests to get wrong namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, I think this change should be kept until you guys decide to straighten this up.

<AssemblyName>Microsoft.Python.Analysis.Engine.Tests</AssemblyName>
</PropertyGroup>
<PropertyGroup>
Expand Down