I have a config I loaded up into a dict
. It contains an integer config["logging"]["backup_count"]
. However, type(config["logging"]["backup_count"])
returns object
. So, when I go to pass this into the following:
TimedRotatingFileHandler(log_file, backupCount=config["logging"]["backup_count"], when="midnight", interval=1)
mypy complains that I am trying to put an object
where an int
is expected. Of course, this is fixable by adding some type-casting:
TimedRotatingFileHandler(log_file, backupCount=int(str(config["logging"]["backup_count"])), when="midnight", interval=1)
but this seems clunky. Should I be doing this?
I’m new to mypy and typing in python. I’d like to know the proper protocol for dealing with something like this. Specifically, should I be doing the -to-str-to-int cast or something else?