Open
Description
The following works in ordinary CPython:
def read_seek_tell_test():
a_char: str = read(fd, 1) ############ ATTENTION #############
assert a_char == '('
a_char = read(fd, 1)
assert a_char == 'I'
assert tell(fd) == 2
assert seek(fd, 0, SEEK_SET) == 0
assert seek(fd, 100, SEEK_SET) == 100
assert seek(fd, 2, SEEK_SET) == 2
temp: str = read(fd, -1)
assert temp == 'nteger 4 [])'
assert tell(fd) == 14
if __name__ == '__main__':
integer_asr : str = '(Integer 4 [])'
fd : StringIO = StringIO(integer_asr, 0, 0) ############ ATTENTION ##############
__post_init__(fd) # Issue #1929
stringio_test()
read_seek_tell_test()
because the variable fd
goes into global scope.
LPython complains:
└─(14:11:15 on brian-lasr ✹ ✭)──> ~/CLionProjects/lpython/src/bin/lpython lasr_lexer.py && ./lasr_lexer.out ──(Sun,Jun18)─┘
semantic error: 'fd' is not defined in the scope
--> lasr_lexer.py:87:12
|
87 | assert fd._buf == integer_asr
| ^^^^^^^