Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
please stop treating optionals as booleans
  • Loading branch information
angelcaru committed May 28, 2024
1 parent d313573 commit 81afc4c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion core/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,12 @@ def execute(self, args: list[Value], kwargs: dict[str, Value]) -> RTResult[Value
if res.should_return() and res.func_return_value is None:
return res

ret_value = (value if self.should_auto_return else None) or res.func_return_value or Null.null()
if self.should_auto_return:
ret_value = value
else:
ret_value = res.func_return_value
if ret_value is None:
ret_value = Null.null()
return res.success(ret_value)

def copy(self) -> Function:
Expand Down
4 changes: 2 additions & 2 deletions core/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,8 @@ def failure(self, error: Error) -> RTResult[T]:
def should_return(self) -> bool:
# Note: this will allow you to continue and break outside the current function
return bool(
self.error
or self.func_return_value
self.error is not None
or self.func_return_value is not None
or self.loop_should_continue
or self.loop_should_break
or self.should_exit
Expand Down
3 changes: 2 additions & 1 deletion radon.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def main(argv: list[str]) -> None:
base_core.global_symbol_table.set("argv", base_core.radonify(argv, pos, pos, Context("<global>")))
if source_file is not None:
head, tail = os.path.split(source_file)
os.chdir(head)
if head != "":
os.chdir(head)
with open(tail, "r") as f:
source = f.read()
(result, error, should_exit) = base_core.run(source_file, source)
Expand Down

0 comments on commit 81afc4c

Please sign in to comment.