diff --git a/mathics/eval/files_io/files.py b/mathics/eval/files_io/files.py index 0a1578c3f..14b0980c1 100644 --- a/mathics/eval/files_io/files.py +++ b/mathics/eval/files_io/files.py @@ -200,7 +200,9 @@ def eval_Read( except Exception as e: print(e) - if expr is SymbolEndOfFile: + if expr is None: + result.append(None) + elif expr is SymbolEndOfFile: evaluation.message(name, "readt", tmp, String(stream.name)) return SymbolFailed elif isinstance(expr, BaseElement): @@ -275,5 +277,10 @@ def eval_Read( return [from_python(part) for part in result] elif result_len == 1: result = result[0] + if SymbolHoldExpression in types: + if hasattr(result, "head") and result.head is SymbolHold: + return from_python(result) + else: + return Expression(SymbolHold, from_python(result)) return from_python(result) diff --git a/test/builtin/files_io/test_files.py b/test/builtin/files_io/test_files.py index 17c11a2d5..c1decd9b3 100644 --- a/test/builtin/files_io/test_files.py +++ b/test/builtin/files_io/test_files.py @@ -295,6 +295,18 @@ def test_close(): "{{a, 1}}", "", ), + ( + 'ReadList[StringToStream["(**)"], Expression]', + None, + "{Null}", + "", + ), + ( + 'ReadList[StringToStream["Hold[1+2]"], Expression]', + None, + "{Hold[1 + 2]}", + "", + ), ('stream = StringToStream["Mathics is cool!"];', None, "Null", ""), ("SetStreamPosition[stream, -5]", ("Invalid I/O Seek.",), "0", ""), (