3 ms·
> It would have been better to an addition start, run, exec method that does that kind of things. Even if for usage it is an inch more complicated to use with a
by lmm 2y ago
> It would have been better to an addition start, run, exec method that does that kind of things. Even if for usage it is an inch more complicated to use with an additional call.
That breaks RAII - you shouldn't give the user a way to create the object in an invalid state. Although if it's intended to be used as a context manager anyway then maybe doing it on context enter rather than on init would be nicer.
- greatgib 2y agoDoesn't necessarily have to be in an invalid state. You can have your object with a none value for the socket or a state like "not_started" and the different method will look at that to handle everything properly. Also, it was not supposed to be used in a context manager as there is just a close method but it is the caller that decided to wrap it in a context. But as what you suggest, indeed it would have been a great idea to add an __enter__ and do the starting there are as it would be the proper way.