[issue40124] Clearer assertion error

Kyle Stanley report at bugs.python.org
Thu Apr 2 00:17:51 EDT 2020


Kyle Stanley <aeros167 at gmail.com> added the comment:

> Do we really want this to be just an assert, or do we want to raise another type of exception?

IMO, we should look into converting this into an exception. Mistakenly having a task await StreamWriter.drain() at the same time as another is calling StreamWriter.write() does seem like a reasonable programming error that should preferably have an informative error message. Optimally, assertions shouldn't occur from normal programming errors in production.

The tricky part is figuring out how to implement it properly. I'm not 100% certain that we can make any guarantees that when the _drain_waiter future hasn't been cancelled and not set to None that someone is mistakenly doing the above. It could potentially trigger from other errors.

Either way though, I think just adding a message to the assert could end up being misleading if someone else encounters this in production for another reason. Instead, I think we could leave a comment there for now and in the long term figure out how to properly implement the exception or warning. We also need a reliable way to reproduce it, mainly for the purpose of writing a new test to ensure the exception is correctly triggered when someone makes the above programming error.

----------
nosy: +aeros

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40124>
_______________________________________


More information about the Python-bugs-list mailing list