Skip to content
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: 3 additions & 0 deletions src/Analysis/Ast/Impl/Types/PythonClassType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public override string Documentation {

// Constructor call
public override IMember CreateInstance(IArgumentSet args) {
if (args == null) {
return new PythonInstance(this);
}
var builtins = DeclaringModule.Interpreter.ModuleResolution.BuiltinsModule;
// Specializations
switch (Name) {
Expand Down
27 changes: 27 additions & 0 deletions src/LanguageServer/Test/HoverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,32 @@ private static void AssertHover(HoverSource hs, IDocumentAnalysis analysis, Sour
hover.range.Should().Be((Range)span.Value);
}
}

[TestMethod, Priority(0)]
public async Task GenericMethodReturningTypeVar() {
// Building hover documentation for a generic method whose return type is a
// TypeVar (here resolved to a collection type) must not throw.
const string code = @"
from typing import Generic, Type, TypeVar

T = TypeVar('T')

class Container(Generic[T]):
def __init__(self, schema: Type[T]) -> None:
self.schema = schema

def get(self) -> T: ...

c = Container(schema=dict)
c.get()
";
var analysis = await GetAnalysisAsync(code);
var hs = new HoverSource(new PlainTextDocumentationSource());

var hover = hs.GetHover(analysis, new SourceLocation(13, 4));

hover.Should().NotBeNull();
hover.contents.value.Should().Contain("get");
}
}
}