mypy
mypy copied to clipboard
Need type annotation on context_manager variable
error: Need type annotation for "redis_cluster" [var-annotated]
Code:
async with (RedisMap(self.conf_redis["host"], self.conf_redis["port"], use_async=True) as redis_map,
RedisCluster(host=self.conf_redis_cluster["host"],
port=self.conf_redis_cluster["port"],
socket_timeout=REDIS_TIMEOUT,
decode_responses=True) as redis_cluster,
NetatmoClientAsync() as netatmo_client):
await self.order_manager.run(url, redis_map, redis_cluster, netatmo_client)
Mypy version: 1.8.0 Python version: 3.10
What’s the type definition for RedisCluster? This isn’t a bug - it’s a generic class, but your instantiation call didn’t specify the type for that. Mypy is therefore erroring to indicate you need to specify it manually. Either annotate the variable, or change the call to be like RedisCluster[type1, type2](…).