Azure / msrest-for-python

The runtime library "msrest" for AutoRest generated Python clients.
MIT License
41 stars 64 forks source link

Allow using ConsumptionManagementClient as a context manager for HTTPS connections reuse #239

Open pdecat opened 3 years ago

pdecat commented 3 years ago

Hi,

it would be awesome if ConsumptionManagementClient could be used as a context manager just like ComputeClientManagement.

Currently, this does not work as ConsumptionManagementClient only inherits from object and has no __enter__/__exit__ methods, unlike ComputeClientManagement that does inherit from msrest.service_client.SDKClient:

consumption_client = ConsumptionManagementClient(**parameters)
with consumption_client as client:
  response = client.price_sheet.get(expand="meterDetails", raw=True) 

A dirty work-around that works:

consumption_client = ConsumptionManagementClient(**parameters)
with consumption_client._client:
  response = consumption_client.price_sheet.get(expand="meterDetails", raw=True) 

Related: https://github.com/Azure/msrest-for-python/issues/132#issuecomment-450938697