python-zabbix-utils icon indicating copy to clipboard operation
python-zabbix-utils copied to clipboard

AsyncZabbixAPI can't be used in `with` statement like ZabbixAPI

Open orhantugrul opened this issue 1 year ago • 0 comments

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

  • ZabbixAPI automatically logs in during the __init__ function.
  • AsyncZabbixAPI does 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

orhantugrul avatar Sep 05 '24 00:09 orhantugrul