def foo():
    file = None
    try:
        file = open('test.json')
    except Exception:
        pass

    file.name # error