IOError as the base class for aiohttp exceptions #5823
-
Hi. I've been using aiohttp a little bit and I like it very much, easy to use and has suited my needs. My discussion point, per the title, is mostly about semantics but I also have an example where the change would simplify my project slightly. This is a small issue for what I am writing. Basically, I have a client class that contains a consumer class, and the client class acts as a bridge for the consumer class: class Consumer():
def consume(service_name):
""" Preparing HTTP request """
async with self.http_session.request(...) as resp:
response = await resp.read()
""" Do things with response """
class Client():
def __init__():
self.consumer = Consumer()
def consume(service_name):
try:
self.consumer.consume(service_name)
except Exception:
""" ???? """ The problem here is that I might want to do different things depending on if the I/O throws, preparation throws or the post-processing throws. I know this can be solved in many different ways, like putting the request in a try-except block and re-raising an I'm bringing this up to discussion instead of raising an error because I'm not sure if you already considered this and decided against it, or if it would be hard to implement with how your code base is written. As I said in the beginning, it's mostly about semantics but I think it's worth thinking about! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Well, the documentation suggests IOError is deprecated, so I guess it'd be OSError (or one of it's subclasses) if anything. Given that these should be OS-related exceptions, I don't think it makes sense for all the aiohttp exceptions to be subclassed from that. The only ones that make sense are the connection errors, which according to the documentation are already subclassed from OSError (atleast the client ones): |
Beta Was this translation helpful? Give feedback.
Well, the documentation suggests IOError is deprecated, so I guess it'd be OSError (or one of it's subclasses) if anything.
https://docs.python.org/3/library/exceptions.html#IOError
Given that these should be OS-related exceptions, I don't think it makes sense for all the aiohttp exceptions to be subclassed from that. The only ones that make sense are the connection errors, which according to the documentation are already subclassed from OSError (atleast the client ones):
https://docs.aiohttp.org/en/stable/client_reference.html?highlight=exception#aiohttp.ClientOSError