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
11 changes: 9 additions & 2 deletions python/deps/untypy/untypy/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import types
from typing import Optional, Union, List

from untypy.util.display import IndicatorStr
from untypy.error import UntypyTypeError, Frame, Location
from untypy.interfaces import ExecutionContext, TypeChecker, WrappedFunction
from untypy.util.display import IndicatorStr
from untypy.util.return_traces import get_last_return


Expand Down Expand Up @@ -126,8 +126,15 @@ def wrap(self, err: UntypyTypeError) -> UntypyTypeError:

declared = WrappedFunction.find_location(self.fn)
responsable = declared

if responsable is not None:
responsable = responsable.narrow_in_span(self.reti_loc)
if err.expected is not None and err.given is None:
# Missing Return-Value?
err = err.with_note("Did you miss an return statement?")
last_line = responsable.line_no + responsable.line_span - 1
responsable = responsable.narrow_in_span((responsable.file, last_line))
else:
responsable = responsable.narrow_in_span(self.reti_loc)

return err.with_frame(Frame(
return_id.ty,
Expand Down
1 change: 1 addition & 0 deletions python/fileTests
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ checkWithOutputAux yes 1 test-data/testForwardRef2.py
checkWithOutputAux yes 0 test-data/testForwardRef3.py
checkWithOutputAux yes 1 test-data/testForwardRef4.py
checkWithOutputAux yes 1 test-data/testTypesReturn.py
checkWithOutputAux yes 1 test-data/testMissingReturn.py
checkWithOutputAux yes 1 test-data/testTypesSequence1.py
checkWithOutputAux yes 1 test-data/testTypesSequence2.py
checkWithOutputAux yes 1 test-data/testTypesTuple1.py
Expand Down
14 changes: 14 additions & 0 deletions python/test-data/testMissingReturn.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Traceback (most recent call last):
File "test-data/testMissingReturn.py", line 6, in <module>
print(billigStrom(500))
WyppTypeError: got value of wrong type
Did you miss an return statement?

given: None
expected: value of type float

context: billigStrom(kwh: float) -> float
^^^^^
declared at: test-data/testMissingReturn.py:3
caused by: test-data/testMissingReturn.py:4
| pass
Empty file.
6 changes: 6 additions & 0 deletions python/test-data/testMissingReturn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# See: https://github.com/skogsbaer/write-your-python-program/issues/15

def billigStrom(kwh: float) -> float:
pass

print(billigStrom(500))