Ticket #2674 defect closed fixed
t.i.defer.inlineCallbacks documentation issues
| Reported by: | indigo | Owned by: | exarkun |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | core | Keywords: | |
| Cc: | Branch: | branches/inlineCallbacks-docs-2674 | |
| Author: | indigo | Launchpad Bug: |
Description
inlineCallbacks currently allows one to yield a value that is not a Deferred instance without an error. When this is done, it seems to .send() the yielded value back to the generator immediately. I am not sure this is useful behavior, since if you can yield it, you could assign it. The only one case is maybe functions that might return a deferred sometimes; then "yield" serves a function similar to maybeDeferred.
I don't think that's a very common case. It seems more likely to me that yielding a non-deferred is a mistake and should raise an error. Also, it might be useful to have the capability to yield other things from the generator that instruct inlineCallbacks to do other things. For example, call next() in a thread, or maybe give it to runInteraction of an adbapi.ConnectionPool. This is not possible with the current behavior.
Arguments against the usefulness of the current behavior aside, it should at least be documented, if not depreciated or changed.
Also, I found it somewhat surprising that "returnValue(Deferred())" causes an error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twisted/internet/defer.py", line 746, in gotResult
_inlineCallbacks(r, g, deferred)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twisted/internet/defer.py", line 733, in _inlineCallbacks
deferred.callback(e.value)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twisted/internet/defer.py", line 239, in callback
self._startRunCallbacks(result)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twisted/internet/defer.py", line 304, in _startRunCallbacks
self._runCallbacks()
--- <exception caught here> ---
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twisted/internet/defer.py", line 317, in _runCallbacks
self.result = callback(self.result, *args, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twisted/internet/defer.py", line 746, in gotResult
_inlineCallbacks(r, g, deferred)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twisted/internet/defer.py", line 733, in _inlineCallbacks
deferred.callback(e.value)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/twisted/internet/defer.py", line 238, in callback
assert not isinstance(result, Deferred)
exceptions.AssertionError:
especially since .addCallback(lambda _: Deferred()) is not an error.

