mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Need type annotation on context_manager variable

Open Falgu9 opened this issue 1 year ago • 1 comments

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

Falgu9 avatar Feb 08 '24 15:02 Falgu9

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](…).

TeamSpen210 avatar Feb 08 '24 15:02 TeamSpen210