Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: replace deprecated defer.returnValue() with return #102

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/examples/fd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def call_remote_verbose(obj, method, *args, **kwargs):
print(f'calling {method}{args}', end=' = ')
result = yield obj.callRemote(method, *args, **kwargs)
print(repr(result))
defer.returnValue(result)
return result


@defer.inlineCallbacks
Expand All @@ -40,7 +40,7 @@ def main(reactor):
print('obtained remote object')
except Exception as e:
print(f'failed obtaining remote object: {e}')
defer.returnValue(None)
return None

# Open this source file. Ask remote to read it and return byte count.
with open(__file__, 'rb') as f:
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/fd_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def main(reactor):
except Exception as e:
print(f'failed connecting to dbus: {e}')
reactor.stop()
defer.returnValue(None)
return None

print('connected to dbus')
object = FDObject(PATH)
Expand Down
10 changes: 3 additions & 7 deletions doc/tutorial.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ operator will be returned from the +yield+ statement. Alternatively, if the
operation resulted in an exception, the exception will be re-thrown from the
+yield+ statement.

The return value of functions decorated with +defer.inlineCallbacks+ is a
deferred. Due to the nature of generator functions, inline callbacks methods
cannot use the traditional +return+ keyword to return the result of the
asynchronous operation. Instead, they must use +defer.returnValue()+ to
return the result. If +defer.returnValue()+ is not used, the deferred
returned by the decorated function will result in +None+
The return value of functions decorated with +defer.inlineCallbacks+ is
propagated using +return+ as usual.

.Inline Callbacks Example
[source,python]
Expand All @@ -67,7 +63,7 @@ def checkIPUsage( ip_addr ):

if ip_addr in ip_txt:
# True will become the result of the Deferred
defer.returnValue( True )
return True
else:
# Will trigger an errback
raise Exception('IP NOT FOUND')
Expand Down
Loading