Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
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
6 changes: 6 additions & 0 deletions src/Analysis/Ast/Impl/Analyzer/Symbols/SymbolCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ private PythonFunctionOverload GetOverloadFromStub(FunctionDefinition node) {
}

private bool TryAddProperty(FunctionDefinition node, IPythonType declaringType) {
// We can't add a property to an unknown type. Fallback to a regular function for now.
// TOOD: Decouple declaring types from the property.
if (declaringType.IsUnknown()) {
return false;
}

var dec = node.Decorators?.Decorators;
var decorators = dec != null ? dec.ExcludeDefault().ToArray() : Array.Empty<Expression>();

Expand Down
4 changes: 3 additions & 1 deletion src/Analysis/Ast/Impl/Types/PythonFunctionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ private void ProcessDecorators(FunctionDefinition fd) {
break;
case @"property":
case @"abstractproperty":
Debug.Assert(false, "Found property attribute while processing function. Properties should be handled in the respective class.");
// Ignore property decorators if the declaring type is unknown.
// TODO: Restore this to a hard failure once property can handle not having a declaring type.
Debug.Assert(DeclaringType.IsUnknown(), "Found property attribute while processing function. Properties should be handled in the respective class.");
break;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/Analysis/Ast/Test/ClassesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,21 @@ def __init__(self):
// Test run time: typically ~ 20 sec.
sw.ElapsedMilliseconds.Should().BeLessThan(60000);
}

[TestMethod, Priority(0)]
public async Task NestedProperty() {
const string code = @"
class x(object):
def func(self):
@property
def foo(*args, **kwargs):
pass
return 42

a = x().func()
";
var analysis = await GetAnalysisAsync(code);
analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int);
}
}
}