Skip to content
Closed
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
23 changes: 14 additions & 9 deletions src/nagini_translation/lib/typeinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def visit_name_expr(self, node: mypy.nodes.NameExpr):
is_alias = True
break
if (node.name not in LITERALS and not is_alias):
name_type = self.type_of(node)
if not isinstance(name_type, mypy.types.CallableType):
name_type = self.type_of_option(node)
if name_type and not isinstance(name_type, mypy.types.CallableType):
self.set_type(self.prefix + [node.name], name_type,
node.line, col(node))

Expand Down Expand Up @@ -221,7 +221,7 @@ def visit_call_expr(self, node: mypy.nodes.CallExpr):
self.visit(a)
self.visit(node.callee)

def type_of(self, node):
def type_of_option(self, node):
if hasattr(node, 'node') and isinstance(node.node, mypy.nodes.MypyFile):
return node.fullname
if hasattr(node, 'node') and isinstance(node.node, mypy.nodes.TypeInfo):
Expand Down Expand Up @@ -253,12 +253,17 @@ def type_of(self, node):
if tuple(fullname) in self.type_vars:
result = self.type_vars[tuple(fullname)]
return result
msg = self.path + ':' + str(node.get_line()) + ': error: '
if isinstance(node, mypy.nodes.FuncDef):
msg += 'Encountered Any type. Type annotation missing?'
else:
msg += 'dead.code'
raise TypeException([msg])

def type_of(self, node):
res = self.type_of_option(node)
if res is None:
msg = self.path + ':' + str(node.get_line()) + ': error: '
if isinstance(node, mypy.nodes.FuncDef):
msg += 'Encountered Any type. Type annotation missing?'
else:
msg += 'dead.code'
raise TypeException([msg])
return res

def visit_comparison_expr(self, o: mypy.nodes.ComparisonExpr):
# Weird things seem to happen with is-comparisons, so we ignore those.
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/verification/issues/00285.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/

from typing import Generic, List, TypeVar
from nagini_contracts.contracts import *

T = TypeVar('T')


class GenericResult(Generic[T]):
def __init__(self, data: T):
Ensures(Acc(self.data) and self.data is data) # type: ignore
self.data = data


class foo():
def bar(self) -> GenericResult[List[int]]:
return GenericResult[List[int]]([1, 2, 3])
Loading