python-zabbix-utils
python-zabbix-utils copied to clipboard
AsyncZabbixAPI can't be used in `with` statement like ZabbixAPI
The AsyncZabbixAPI class cannot be used in a with statement like the ZabbixAPI class. This is due to a difference in the initialization process between the two classes.
Current Behavior
-
ZabbixAPIautomatically logs in during the__init__function. -
AsyncZabbixAPIdoes not automatically log in during initialization.
Expected Behavior
Users expect to be able to use AsyncZabbixAPI in a with statement similar to ZabbixAPI for consistent usage patterns.
Proposed Solution
Perform the asynchronous login in the __aenter__ method.
class AsyncZabbixAPI:
async def __aenter__(self):
await self.login()
return self