I’m trying to create a function that reloads a global bank:
import json
type Bank = dict[str, dict[str: int | float]]
def get_ball() -> None:
"""
_summary_
Reloads the bank dict from the bank.json file
"""
global bank
with open("bank.json", "r") as f:
bank: Bank = json.load(f) # Error
# bank = json.load(f) # Works fine
print(bank)
get_ball()
print(bank)
But it raises a SyntaxError: annotated name ‘bank’ can’t be global
When it doesn’t have an assigned type it works just fine (see the commented out line). What do I have to do?
New contributor
Patrovsky games is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.