'Error occurs in pycharm debugger is gone when `print()` is added

The code below fails only in pycharm debugger when the print statement is commented out and a breakpoint is placed on the last line containing a pass. It works fine in the debugger if the print statement is

import json


def foo(fp):
    with open(fp) as x, open(fp) as y:
        xx = json.load(x)
        yy = json.load(y)
    # print()  # uncomment this line and the error is gone
    pass  # place a breakpoint on this line


if __name__ == '__main__':
    foo('x.json')

x.json is an empty json file.

Versions:

PyCharm: 2022.1.1
python: 3.10.4

Error:

/usr/local/opt/[email protected]/bin/python3.10 /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 50489 --file "/Users/user/Library/Application Support/JetBrains/PyCharm2022.1/scratches/scratch_3.py"
Connected to pydev debugger (build 221.5591.52)
Traceback (most recent call last):
  File "/Users/user/Library/Application Support/JetBrains/PyCharm2022.1/scratches/scratch_3.py", line 5, in foo
    with open(fp) as x, open(fp) as y:
TypeError: 'dict' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1491, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/user/Library/Application Support/JetBrains/PyCharm2022.1/scratches/scratch_3.py", line 13, in <module>
    foo('x.json')
  File "/Users/user/Library/Application Support/JetBrains/PyCharm2022.1/scratches/scratch_3.py", line 5, in foo
    with open(fp) as x, open(fp) as y:
TypeError: 'TypeError' object is not callable
python-BaseException


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source