Commit 15a4c29b authored by Wolfgang Rohdewald's avatar Wolfgang Rohdewald
Browse files

pylint: remove unnecessary else/elif after return

parent 562ae033
......@@ -272,11 +272,10 @@ class ParallelAnimationGroup(QParallelAnimationGroup, StrMixin):
state = self.state()
if state == QAbstractAnimation.Stopped:
return 'stopped'
elif state == QAbstractAnimation.Running:
if state == QAbstractAnimation.Running:
return 'running'
else:
assert False
return None
assert False
return None
def __str__(self):
"""for debugging"""
......
......@@ -412,7 +412,7 @@ class Client(pb.Referenceable):
# before the animated tile reaches its end position
animate()
return answer
elif message == Message.AskForClaims:
if message == Message.AskForClaims:
# no need to start an animation. If we did the below standard clause, this is what
# could happen:
# 1. user says Chow
......
......@@ -232,22 +232,21 @@ class DeferredBlock(StrMixin):
if Debug.deferredBlock:
self.debug('IGN', request.pretty())
return
else:
request.gotAnswer(result)
if hasattr(request.user, 'pinged'):
# a Client (for robots) does not have it
request.user.pinged()
if Debug.deferredBlock:
self.debug('ANS', request.pretty())
if hasattr(request.answer, 'notifyAction'):
block = DeferredBlock(self.table, temp=True)
receivers = request.answer.receivers(request)
if receivers:
block.tell(
request.player,
receivers,
request.answer,
notifying=True)
request.gotAnswer(result)
if hasattr(request.user, 'pinged'):
# a Client (for robots) does not have it
request.user.pinged()
if Debug.deferredBlock:
self.debug('ANS', request.pretty())
if hasattr(request.answer, 'notifyAction'):
block = DeferredBlock(self.table, temp=True)
receivers = request.answer.receivers(request)
if receivers:
block.tell(
request.player,
receivers,
request.answer,
notifying=True)
self.outstanding -= 1
assert self.outstanding >= 0, '__gotAnswer: outstanding %d' % self.outstanding
self.callbackIfDone()
......
......@@ -49,7 +49,7 @@ class DifferModel(QAbstractTableModel):
column = index.column()
if role == Qt.DisplayRole:
return diff[column]
elif role == Qt.TextAlignmentRole:
if role == Qt.TextAlignmentRole:
return int(Qt.AlignLeft | Qt.AlignVCenter)
return None
......
......@@ -706,7 +706,7 @@ class Game:
return True
if Options.rounds:
return self.roundsFinished >= Options.rounds
elif self.ruleset:
if self.ruleset:
# while initialising Game, ruleset might be None
return self.roundsFinished >= self.ruleset.minRounds
return None
......
......@@ -75,11 +75,11 @@ class GamesModel(QAbstractTableModel):
# this translation is needed for robot players
names = [i18n(name) for name in unformatted.split('///')]
return ', '.join(names)
elif index.column() == 1:
if index.column() == 1:
dateVal = datetime.datetime.strptime(
unformatted, '%Y-%m-%dT%H:%M:%S')
return dateVal.strftime('%c')
elif index.column() == 0:
if index.column() == 0:
return int(unformatted)
return QAbstractTableModel.data(self, index, role)
......
......@@ -643,7 +643,7 @@ class Hand(StrMixin):
return True
if self.won and not (other.arranged and other.won):
return True
elif not (self.arranged and self.won) and other.won:
if not (self.arranged and self.won) and other.won:
return False
return (self.intelligence.handValue(self)
> self.intelligence.handValue(other))
......
......@@ -870,8 +870,7 @@ class HumanClient(Client):
if Debug.connections:
logDebug('sending logout to server for {}'.format(self))
return self.callServer('logout').addCallback(loggedout, conn)
else:
return succeed(None)
return succeed(None)
def __logCallServer(self, *args):
"""for Debug.traffic"""
......
......@@ -49,13 +49,12 @@ class Fmt(string.Formatter):
idpar = 'SELF'
if kwargs[idpar] is None:
return 'None'
elif Debug.neutral:
if Debug.neutral:
return '....'
return Fmt.num_encode(id(kwargs[idpar]))
elif key == 'self':
if key == 'self':
return kwargs['SELF']
else:
return kwargs[key]
return kwargs[key]
Fmt.formatter = Fmt()
......
......@@ -119,15 +119,14 @@ class Url(str, StrMixin):
# just wait for that server to appear
if self.__serverListening():
return result
else:
if waiting == 0:
self.__startLocalServer()
elif waiting > 30:
logDebug('Game %s: Server %s not available after 30 seconds, aborting' % (
SingleshotOptions.game, self))
raise CancelledError
return deferLater(Internal.reactor, 1, self.startServer, result, waiting + 1)
elif which('qdbus'):
if waiting == 0:
self.__startLocalServer()
elif waiting > 30:
logDebug('Game %s: Server %s not available after 30 seconds, aborting' % (
SingleshotOptions.game, self))
raise CancelledError
return deferLater(Internal.reactor, 1, self.startServer, result, waiting + 1)
if which('qdbus'):
try:
stdoutdata, stderrdata = subprocess.Popen(
['qdbus',
......@@ -341,7 +340,7 @@ class LoginDlg(QDialog):
"""find out what ruleset to use"""
if Options.ruleset:
return Options.ruleset
elif Internal.autoPlay or bool(Options.host):
if Internal.autoPlay or bool(Options.host):
return Ruleset.selectableRulesets()[0]
return self.cbRuleset.current
......
......@@ -229,7 +229,7 @@ class Meld(TileList, StrMixin):
"""meld state: exposed or not"""
if self.case.islower():
return True
elif len(self) == 4:
if len(self) == 4:
return self.case[1:3].islower()
return False
......@@ -316,17 +316,17 @@ class Meld(TileList, StrMixin):
# pylint: disable=too-many-return-statements
if self.isBonus:
return i18nc('kajongg meld type', 'Bonus')
elif self.isSingle:
if self.isSingle:
return i18nc('kajongg meld type', '&single')
elif self.isPair:
if self.isPair:
return i18nc('kajongg meld type', '&pair')
elif self.isChow:
if self.isChow:
return i18nc('kajongg meld type', '&chow')
elif self.isPung:
if self.isPung:
return i18nc('kajongg meld type', 'p&ung')
elif self.isClaimedKong:
if self.isClaimedKong:
return i18nc('kajongg meld type', 'c&laimed kong')
elif self.isKong:
if self.isKong:
return i18nc('kajongg meld type', 'k&ong')
return i18nc('kajongg meld type', 'rest of tiles')
......@@ -334,7 +334,7 @@ class Meld(TileList, StrMixin):
"""the translated name of the state"""
if self.isBonus or self.isClaimedKong:
return ''
elif self.isExposed:
if self.isExposed:
return i18nc('kajongg meld state', 'Exposed')
return i18nc('kajongg meld state', 'Concealed')
......
......@@ -66,23 +66,22 @@ class Message:
cls = value.__class__
if cls in (Tile, TileList, Meld, MeldList):
return str(value)
elif isinstance(value, Wind):
if isinstance(value, Wind):
return str(value)
elif isinstance(value, Message):
if isinstance(value, Message):
return value.name
elif isinstance(value, (list, tuple)):
if isinstance(value, (list, tuple)):
if isinstance(value, tuple) and isinstance(value[0], Message):
if value[1] is None or value[1] == []:
return value[0].name
return type(value)([Message.jelly(key, x) for x in value])
elif isinstance(value, dict):
if isinstance(value, dict):
return {Message.jelly('key', x): Message.jelly('value', y) for x, y in value.items()}
else:
if not isinstance(value, (int, bytes, str, float, type(None))):
raise Exception(
'callRemote got illegal arg: %s %s(%s)' %
(key, type(value), str(value)))
return value
if not isinstance(value, (int, bytes, str, float, type(None))):
raise Exception(
'callRemote got illegal arg: %s %s(%s)' %
(key, type(value), str(value)))
return value
@staticmethod
def jellyAll(args, kwargs):
......
......@@ -786,23 +786,21 @@ class Rule(RuleBase):
(id(hand) %
10000, cacheKey, result))
return result
else:
if Debug.ruleCache:
if hand.ruleCache[cacheKey] != func(*args):
hand.player.game.debug(
'cacheKey=%s rule=%s func:%s args:%s' %
(cacheKey, srcClass, func, args))
hand.player.game.debug(
' hand:%s/%s' %
(id(hand), hand))
hand.player.game.debug(
' cached:%s ' %
str(hand.ruleCache[cacheKey]))
hand.player.game.debug(
' real:%s ' %
str(func(*args)))
return hand.ruleCache[cacheKey]
return result
if Debug.ruleCache:
if hand.ruleCache[cacheKey] != func(*args):
hand.player.game.debug(
'cacheKey=%s rule=%s func:%s args:%s' %
(cacheKey, srcClass, func, args))
hand.player.game.debug(
' hand:%s/%s' %
(id(hand), hand))
hand.player.game.debug(
' cached:%s ' %
str(hand.ruleCache[cacheKey]))
hand.player.game.debug(
' real:%s ' %
str(func(*args)))
return hand.ruleCache[cacheKey]
return classmethod(wrapper) if clsMethod else staticmethod(wrapper)
def __init__(self, name, definition='', points=0, doubles=0, limits=0,
......
......@@ -331,9 +331,8 @@ class StandardMahJongg(MJRule):
if val0 == 8:
return {Tile(group, val0 - 1)}
return {Tile(group, val0 - 1), Tile(group, val0 + 2)}
else:
assert val0 + 2 == val1, 'group:%s values:%s' % (group, values)
return {Tile(group, val0 + 1)}
assert val0 + 2 == val1, 'group:%s values:%s' % (group, values)
return {Tile(group, val0 + 1)}
def winningTileCandidates(cls, hand):
# pylint: disable=too-many-locals,too-many-return-statements,too-many-branches,too-many-statements
......@@ -520,7 +519,7 @@ class WrigglingSnake(MJRule):
values = set(hand.values)
if len(values) < 12:
return set()
elif len(values) == 12:
if len(values) == 12:
# one of 2..9 or a wind is missing
if hand.values.count(1) < 2:
# and the pair of 1 is incomplete too
......
......@@ -113,14 +113,13 @@ class RuleItem(RuleTreeItem):
content = self.rawContent
if column == 0:
return content.name
if isinstance(content, ParameterRule):
if column == 1:
return content.parameter
else:
if isinstance(content, ParameterRule):
if column == 1:
return content.parameter
else:
if not hasattr(content.score, str(column)):
column = colNames[column]
return getattr(content.score, column)
if not hasattr(content.score, str(column)):
column = colNames[column]
return getattr(content.score, column)
return ''
def tooltip(self):
......@@ -222,7 +221,7 @@ class RuleModel(TreeModel):
if result == 'doubles':
return 'x2'
return i18nc('kajongg', result)
elif role == Qt.TextAlignmentRole:
if role == Qt.TextAlignmentRole:
leftRight = Qt.AlignLeft if section == 0 else Qt.AlignRight
return int(leftRight | Qt.AlignVCenter)
return None
......@@ -266,10 +265,9 @@ class EditableRuleModel(RuleModel):
oldParameter = content.parameter
if isinstance(content, BoolRule):
return False, ''
else:
if content.parameter != value:
dirty = True
content.parameter = value
if content.parameter != value:
dirty = True
content.parameter = value
message = content.validate()
if message:
content.parameter = oldParameter
......
......@@ -494,7 +494,7 @@ class ScoringScene(GameScene):
logDebug('ScoringScene.abort invoked')
if not self.game:
return succeed(True)
elif self.game.finished():
if self.game.finished():
self.game = None
return succeed(True)
return QuestionYesNo(i18n("Do you really want to abort this game?"), always=True).addCallback(answered)
......
......@@ -605,8 +605,7 @@ def scoreGame():
gameSelector.close()
if selected is not None:
return ScoringGame.loadFromDB(selected)
else:
selectDialog = SelectPlayers()
if not selectDialog.exec_():
return None
return ScoringGame(list(zip(Wind.all4, selectDialog.names)), selectDialog.cbRuleset.current)
selectDialog = SelectPlayers()
if not selectDialog.exec_():
return None
return ScoringGame(list(zip(Wind.all4, selectDialog.names)), selectDialog.cbRuleset.current)
......@@ -88,13 +88,12 @@ class ScorePlayerItem(ScoreTreeItem):
"""return the content stored in this node"""
if column == 0:
return i18n(self.rawContent[0])
else:
try:
return self.hands()[column - 1]
except IndexError:
# we have a penalty but no hand yet. Should
# not happen in practical use
return None
try:
return self.hands()[column - 1]
except IndexError:
# we have a penalty but no hand yet. Should
# not happen in practical use
return None
def hands(self):
"""a small helper"""
......@@ -205,8 +204,7 @@ class ScoreModel(TreeModel):
else:
content = str(content.balance)
return content
else:
return '' if column > 0 else item.content(0)
return '' if column > 0 else item.content(0)
if role == Qt.TextAlignmentRole:
return int(Qt.AlignLeft | Qt.AlignVCenter) if index.column() == 0 else int(Qt.AlignRight | Qt.AlignVCenter)
if role == Qt.FontRole:
......
......@@ -209,8 +209,7 @@ class MJServer:
'sending %d tables to %s: %s' %
(len(tables), user.name, data))
return self.callRemote(user, 'newTables', data)
else:
return succeed([])
return succeed([])
def _lookupTable(self, tableid):
"""return table by id or raise exception"""
......
......@@ -312,7 +312,7 @@ class ServerTable(Table, StrMixin):
if msg.answer == Message.NO:
self.proposeGameId(gameid + 1)
return
elif msg.answer != Message.OK:
if msg.answer != Message.OK:
raise srvError(
pb.Error,
'collectGameIdAnswers got neither NO nor OK')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment