kr8s-org / kr8s

A batteries-included Python client library for Kubernetes that feels familiar for folks who already know how to use kubectl
https://kr8s.org
BSD 3-Clause "New" or "Revised" License
839 stars 45 forks source link

Add a helpful exception when forgetting to await an async class #396

Closed jacobtomlinson closed 5 months ago

jacobtomlinson commented 5 months ago

Adding a little check to ensure that an async object has been correctly awaited.

Before

>>> from kr8s.asyncio.objects import Pod
>>> pod = Pod({"metadata": {"name": "foo"}})  # Oops we forgot to await this
>>> await pod.create()
...
AttributeError: 'NoneType' object has no attribute 'call_api'

After

>>> from kr8s.asyncio.objects import Pod
>>> pod = Pod({"metadata": {"name": "foo"}})  # Oops we forgot to await this
>>> await pod.create()
...
RuntimeError: RuntimeError: <Pod foo> has not been initialized with an API object. Did you forget to await it?
codecov[bot] commented 5 months ago

Codecov Report

Attention: Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.27%. Comparing base (87063fc) to head (fbe9594). Report is 105 commits behind head on main.

Files with missing lines Patch % Lines
kr8s/_objects.py 92.30% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #396 +/- ## ========================================== + Coverage 94.61% 95.27% +0.65% ========================================== Files 29 29 Lines 3141 3471 +330 ========================================== + Hits 2972 3307 +335 + Misses 169 164 -5 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.