@xyzzy is having a bit of indigestion and will have to have a little purging time for the next 24 hours or so. Sit tight and wait around, ye shall soon have the opportunity to get ye FLASK. #bots
Recently, I've been working with the Mastodon.py package while creating #bots. I am extending the functionality through my own implementation and actually encountered a problem while attempting to abstract the API.
The API provides its own exceptions for invalid arguments and data not existing, which is relevant to the user, but rate limits and connection errors might be better if hidden away and allowing my package to handle them initially, to abstract things like a dropped connection.
My problem came in how I could do this, and I did some research and found the #Python context-manager utils.
With a context manager, a single value should be yielded. The code will then execute after the yield when the block is exited. This made me realize that I can implement the API as a generator and introduce async functionality. During a dropped connection or rate limit, I can simply not hold onto the yield and await and allow the generator and context manager to do the rest.