Skip to content

Commit

Permalink
Merge pull request buildbot#7980 from cjwatson/remove-defer-returnValue
Browse files Browse the repository at this point in the history
Stop using twisted.internet.defer.returnValue
  • Loading branch information
p12tic authored Sep 13, 2024
2 parents 49a607f + d7980fa commit 8193680
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 21 deletions.
9 changes: 0 additions & 9 deletions common/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ check_long_lines() {
}


check_yield_defer_returnValue() {
local yields=false
if git diff "$REVRANGE" | grep '+.*yield defer.returnValue'; then
yields=true
fi
$yields
}

check_relnotes() {
if git diff --exit-code "$REVRANGE" master/docs/relnotes/index.rst >/dev/null 2>&1; then
return 1
Expand Down Expand Up @@ -168,7 +160,6 @@ fi
status "checking formatting"
check_tabs && not_ok "$REVRANGE adds tabs"
check_long_lines && warning "$REVRANGE adds long lines"
check_yield_defer_returnValue && not_ok "$REVRANGE yields defer.returnValue"

status "checking for use of sa.Table"
check_sa_Table || warning "use (buildbot.util.)sautils.Table instead of sa.Table"
Expand Down
3 changes: 0 additions & 3 deletions master/docs/developer/style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ The key points to notice here:
* Use the decorator form of ``inlineCallbacks``.
* In most cases, the result of a ``yield`` expression should be assigned to a variable.
It can be used in a larger expression, but remember that Python requires that you enclose the expression in its own set of parentheses.
* Python does not permit returning a value from a generator, so statements like ``return xval + y`` are invalid.
Instead, yield the result of ``defer.returnValue``.
For clarity, follow it with a bare ``return``, unless it is the last statement in the function.

The great advantage of ``inlineCallbacks`` is that it allows you to use all of the usual Pythonic control structures in their natural form.
In particular, it is easy to represent a loop or even nested loops in this style without losing any readability.
Expand Down
8 changes: 3 additions & 5 deletions worker/buildbot_worker/commands/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,13 @@ def _clobber(self, dummy, path, chmodDone=False):
# permissions and re-try the rm -rf.
if not chmodDone:
rc = yield self._tryChmod(rc, path)
defer.returnValue(rc)
return rc

@defer.inlineCallbacks
def _tryChmod(self, rc, path):
assert isinstance(rc, int)
if rc == 0:
defer.returnValue(0)
# pylint: disable=unreachable
return # pragma: no cover
return 0
# Attempt a recursive chmod and re-try the rm -rf after.

command = ["chmod", "-Rf", "u+rwx", path]
Expand All @@ -158,7 +156,7 @@ def _tryChmod(self, rc, path):
self.command = c
rc = yield c.start()
rc = yield self._clobber(rc, path, True)
defer.returnValue(rc)
return rc


class CopyDirectory(base.Command):
Expand Down
2 changes: 1 addition & 1 deletion worker/buildbot_worker/msgpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def get_message_result(self, msg):
self.seq_number = self.seq_number + 1
self.sendMessage(msg, isBinary=True)
res1 = yield d
defer.returnValue(res1)
return res1

def onClose(self, wasClean, code, reason):
if self.debug:
Expand Down
2 changes: 1 addition & 1 deletion worker/buildbot_worker/pb.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def remote_setBuilderList(self, wanted):
"it now"
)

defer.returnValue(retval)
return retval


class BotPb(BotPbLike, pb.Referenceable):
Expand Down
2 changes: 1 addition & 1 deletion worker/buildbot_worker/pbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def failedToGetPerspective(self, why, broker):
else:
log.err(why, 'While trying to connect:')
reactor.stop()
defer.returnValue(None)
return

self._failedAttempts += 1
delay = self._timeoutForAttempt(self._failedAttempts)
Expand Down
2 changes: 1 addition & 1 deletion worker/buildbot_worker/test/unit/test_bot_Worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def requestAvatar(self, avatarId, mind, *interfaces):
if self.on_attachment:
yield self.on_attachment(mind)

defer.returnValue((pb.IPerspective, self.perspective, lambda: None))
return pb.IPerspective, self.perspective, lambda: None

def shutdown(self):
return self.mind.broker.transport.loseConnection()
Expand Down

0 comments on commit 8193680

Please sign in to comment.