Commit 5cf1c89b authored by Wolfgang Rohdewald's avatar Wolfgang Rohdewald
Browse files

docstrings: imperatives

parent 216f2652
......@@ -181,7 +181,7 @@ class ParallelAnimationGroup(QParallelAnimationGroup, StrMixin):
group.clear()
def showState(self, newState, oldState):
"""overrides Qt method"""
"""override Qt method"""
if self.debug:
logDebug('G{}: {} -> {} isAlive:{}'.format(
self.uid, self.stateName(oldState), self.stateName(newState), isAlive(self)))
......@@ -335,7 +335,7 @@ class AnimatedMixin:
self.setDrawingOrder()
def getValue(self, pName):
"""gets a current property value"""
"""get a current property value"""
return {'pos': self.pos, 'rotation': self.rotation,
'scale': self.scale}[pName]
......
......@@ -51,7 +51,7 @@ class Background(Resource):
(graphName, self.desktopFileName))
def pixmap(self, size):
"""returns a background pixmap or None for isPlain"""
"""return a background pixmap or None for isPlain"""
self.__pmap = QBrush()
if not self.isPlain:
width = size.width()
......@@ -78,7 +78,7 @@ class Background(Resource):
return QBrush(self.pixmap(size))
def setPalette(self, onto):
"""sets a background palette for widget onto"""
"""set a background palette for widget onto"""
palette = QPalette()
mybrush = self.brush(onto.size())
palette.setBrush(QPalette.Window, mybrush)
......
......@@ -268,7 +268,7 @@ class Board(QGraphicsRectItem, StrMixin):
QGraphicsRectItem.setEnabled(self, enabled)
def _focusableTiles(self, sortDir=Qt.Key_Right):
"""returns a list of all tiles in this board sorted such that
"""return a list of all tiles in this board sorted such that
moving in the sortDir direction corresponds to going to
the next list element.
respect board orientation: Right Arrow should always move right
......@@ -284,7 +284,7 @@ class Board(QGraphicsRectItem, StrMixin):
@hasFocus.setter
def hasFocus(self, value):
"""sets focus on this board"""
"""set focus on this board"""
if isAlive(self):
scene = self.scene()
if isAlive(scene):
......@@ -297,7 +297,7 @@ class Board(QGraphicsRectItem, StrMixin):
@staticmethod
def mapChar2Arrow(event):
"""maps the keys hjkl to arrows like in vi and konqueror"""
"""map the keys hjkl to arrows like in vi and konqueror"""
key = event.key()
if key in Board.arrows:
return key
......@@ -338,7 +338,7 @@ class Board(QGraphicsRectItem, StrMixin):
return uiTile
def uiMeldWithTile(self, uiTile): # pylint: disable=no-self-use
"""returns the UI Meld with uiTile. A Board does not know about melds,
"""return the UI Meld with uiTile. A Board does not know about melds,
so default is to return a Meld with only uiTile"""
return UIMeld(uiTile)
......@@ -391,7 +391,7 @@ class Board(QGraphicsRectItem, StrMixin):
return uiTile
def tilesByElement(self, element):
"""returns all child items holding a uiTile for element"""
"""return all child items holding a uiTile for element"""
return [x for x in self.uiTiles if x.tile is element]
def rotatedLightSource(self):
......@@ -414,7 +414,7 @@ class Board(QGraphicsRectItem, StrMixin):
return QRectF(self.tileFacePos(), self.tileset.faceSize)
def setPos(self, xWidth=0, xHeight=0, yWidth=0, yHeight=0):
"""sets the position in the parent item expressing the position in tile face units.
"""set the position in the parent item expressing the position in tile face units.
The X position is xWidth*facewidth + xHeight*faceheight, analog for Y"""
self.__xWidth = xWidth
self.__xHeight = xHeight
......@@ -710,7 +710,7 @@ class SelectorBoard(CourtBoard):
uiTile.setBoard(self, column, row)
def meldVariants(self, tile, lowerHalf):
"""returns a list of possible variants based on meld. Those are logical melds."""
"""return a list of possible variants based on meld. Those are logical melds."""
# pylint: disable=too-many-locals
assert isinstance(tile, UITile)
wantedTile = tile.tile
......@@ -859,7 +859,7 @@ class FittingView(QGraphicsView):
return QGraphicsView.mouseMoveEvent(self, event)
def drag(self, uiTile):
"""returns a drag object"""
"""return a drag object"""
drag = QDrag(self)
mimeData = MimeData(uiTile)
drag.setMimeData(mimeData)
......
......@@ -112,7 +112,7 @@ class ClientTable(Table):
return '%d(%s %s%s)' % (self.tableid, self.ruleset.name, ','.join(onlineNames), offlineString)
def gameExistsLocally(self):
"""does the game exist in the data base of the client?"""
"""True if the game exists in the data base of the client"""
assert self.gameid
return bool(Query('select 1 from game where id=?', (self.gameid,)).records)
......@@ -158,7 +158,7 @@ class Client(pb.Referenceable):
Internal.scene.mainWindow.updateGUI()
def _tableById(self, tableid):
"""returns table with tableid"""
"""return table with tableid"""
for table in self.tables:
if table.tableid == tableid:
return table
......@@ -318,8 +318,8 @@ class Client(pb.Referenceable):
return result
def ask(self, move, answers):
"""this is where the robot AI should go.
sends answer and one parameter to server"""
"""place the robot AI here.
send answer and one parameter to server"""
delay = 0.0
delayStep = 0.1
myself = self.game.myself
......@@ -333,7 +333,7 @@ class Client(pb.Referenceable):
return succeed(result)
def thatWasMe(self, player):
"""returns True if player == myself"""
"""return True if player == myself"""
if not self.game:
return False
return player == self.game.myself
......
......@@ -430,7 +430,7 @@ class IntDict(defaultdict, StrMixin):
for x in countFilter or self)
def all(self, countFilter=None):
"""returns a list of all tiles defined by countFilter,
"""return a list of all tiles defined by countFilter,
each tile multiplied by its occurrence.
countFilter is an iterator of element names. No countFilter: take all
So all(['we', 'fs']) should return ['we', 'we', 'we', 'we', 'fs']"""
......
......@@ -29,7 +29,7 @@ class Parameter:
self.item = None
def itemValue(self):
"""returns the value of this item"""
"""return the value of this item"""
return self.item.value()
......@@ -48,7 +48,7 @@ class StringParameter(Parameter):
self.item = skeleton.addItem(self.name, self.value, self.default or '')
def itemValue(self):
"""returns the value of this item"""
"""return the value of this item"""
return str(self.item.value())
......
......@@ -59,7 +59,7 @@ class HandId(StrMixin):
self.game.notRotated = self.notRotated
def __scanHandId(self, string, stringIdx):
"""gets the --game option.
"""get the --game option.
stringIdx 0 is the part in front of ..
stringIdx 1 is the part after ..
"""
......@@ -764,7 +764,7 @@ class Game:
yield move
def throwDices(self):
"""sets random living and kongBox
"""set random living and kongBox
sets divideAt: an index for the wall break"""
breakWall = self.randomGenerator.randrange(4)
sideLength = len(self.wall.tiles) // 4
......@@ -901,7 +901,7 @@ class PlayingGame(Game):
Game._saveScores(self)
def nextPlayer(self, current=None):
"""returns the player after current or after activePlayer"""
"""return the player after current or after activePlayer"""
if not current:
current = self.activePlayer
pIdx = self.players.index(current)
......@@ -1013,7 +1013,7 @@ class PlayingGame(Game):
player.name, player.voice))
def dangerousFor(self, forPlayer, tile):
"""returns a list of explaining texts if discarding tile
"""return a list of explaining texts if discarding tile
would be Dangerous game for forPlayer. One text for each
reason - there might be more than one"""
assert isinstance(tile, Tile), tile
......
......@@ -187,7 +187,7 @@ class Games(QDialog):
self.view.hideColumn(0)
def __idxForGame(self, game):
"""returns the model index for game"""
"""return the model index for game"""
for row in range(self.model.rowCount()):
idx = self.model.index(row, 0)
if self.model.data(idx, 0) == game:
......@@ -195,7 +195,7 @@ class Games(QDialog):
return self.model.index(0, 0)
def __getSelectedGame(self):
"""returns the game id of the selected game"""
"""return the game id of the selected game"""
rows = self.selection.selectedRows()
return self.model.data(rows[0], 0) if rows else 0
......
......@@ -77,7 +77,7 @@ class ListComboBox(QComboBox):
self.addItem(i18n(item.name), item)
def findItem(self, search):
"""returns the index or -1 of not found """
"""return the index or -1 of not found """
for idx, item in enumerate(self.items):
if item == search:
return idx
......
......@@ -323,7 +323,7 @@ class Hand(StrMixin):
self.__checkHasExclusiveRules()
def matchingWinnerRules(self):
"""returns a list of matching winner rules"""
"""return a list of matching winner rules"""
matching = [UsedRule(x) for x in self.__matchingRules(self.ruleset.winnerRules)]
limitRule = self.maxLimitRule(matching)
return [limitRule] if limitRule else matching
......@@ -338,7 +338,7 @@ class Hand(StrMixin):
raise Hand.__NotWon(fmt('exclusive rule {exclusive} does not win'))
def __setLastMeld(self):
"""sets the shortest possible last meld. This is
"""set the shortest possible last meld. This is
not yet the final choice, see __applyBestLastMeld"""
self.__lastMeld = None
if self.lastTile and self.__won:
......@@ -422,7 +422,7 @@ class Hand(StrMixin):
return ' '.join(parts).strip()
def __add__(self, addTile):
"""returns a new Hand built from this one plus addTile"""
"""return a new Hand built from this one plus addTile"""
assert addTile.isConcealed, 'addTile %s should be concealed:' % addTile
# combine all parts about hidden tiles plus the new one to one part
# because something like DrDrS8S9 plus S7 will have to be reordered
......@@ -437,7 +437,7 @@ class Hand(StrMixin):
return Hand(self.player, newString, prevHand=self)
def __sub__(self, subtractTile):
"""returns a copy of self minus subtractTiles.
"""return a copy of self minus subtractTiles.
Case of subtractTile (hidden or exposed) is ignored.
subtractTile must either be undeclared or part of
lastMeld. Exposed melds of length<3 will be hidden."""
......@@ -478,7 +478,7 @@ class Hand(StrMixin):
return Hand(self.player, newString, prevHand=self)
def manualRuleMayApply(self, rule):
"""returns True if rule has selectable() and applies to this hand"""
"""return True if rule has selectable() and applies to this hand"""
if self.__won and rule in self.ruleset.loserRules:
return False
if not self.__won and rule in self.ruleset.winnerRules:
......@@ -667,7 +667,7 @@ class Hand(StrMixin):
@staticmethod
def maxLimitRule(usedRules):
"""returns the rule with the highest limit score or None"""
"""return the rule with the highest limit score or None"""
result = None
maxLimit = 0
usedRules = [x for x in usedRules if x.rule.score.limits]
......
......@@ -152,7 +152,7 @@ class HandBoard(Board):
return self.player.scoringString()
def lowerHalfTiles(self):
"""returns a list with all single tiles of the lower half melds
"""return a list with all single tiles of the lower half melds
without boni"""
return [x for x in self.uiTiles if x.yoffset > 0 and not x.isBonus]
......@@ -160,7 +160,7 @@ class HandBoard(Board):
"""a list of melds for the hand as it should look after sync"""
def newTilePositions(self):
"""returns list(TileAttr) for all tiles except bonus tiles.
"""return list(TileAttr) for all tiles except bonus tiles.
The tiles are not associated to any board."""
result = list()
newUpperMelds = list(self.player.exposedMelds)
......@@ -201,7 +201,7 @@ class HandBoard(Board):
return result
def newBonusPositions(self, bonusTiles, newTilePositions):
"""returns list(TileAttr)
"""return list(TileAttr)
calculate places for bonus tiles. Put them all in one row,
right adjusted. If necessary, extend to the right even
outside of our board"""
......
......@@ -59,7 +59,7 @@ class AIDefault:
def selectDiscard(self, hand):
# pylint: disable=too-many-branches, R0915
# disable warning about too many branches
"""returns exactly one tile for discard.
"""return exactly one tile for discard.
Much of this is just trial and success - trying to get as much AI
as possible with limited computing resources, it stands on
no theoretical basis"""
......@@ -438,7 +438,7 @@ class DiscardCandidates(list):
this.next2 = None
def best(self):
"""returns the candidate with the lowest value"""
"""return the candidate with the lowest value"""
lowest = min(x.keep for x in self)
candidates = sorted(x for x in self if x.keep == lowest)
result = self.player.game.randomGenerator.choice(
......
......@@ -390,7 +390,7 @@ def removeInvalidCommits(csvFile):
Clone.removeObsolete()
def readGames(csvFile):
"""returns a dict holding a frozenset of games for each variant"""
"""return a dict holding a frozenset of games for each variant"""
if not os.path.exists(csvFile):
return
allRowsGenerator = neutralize(Csv.reader(csvFile))
......
......@@ -118,7 +118,7 @@ class Help:
@staticmethod
def __getDocUrl(languages):
"""returns the best match for the online user manual"""
"""return the best match for the online user manual"""
from twisted.web import client
def processResult(unusedResult, fallbacks):
......@@ -283,7 +283,7 @@ class KDialog(CaptionMixin, QDialog):
self.layout().addWidget(self.buttonBox)
def button(self, buttonCode):
"""returns the matching button"""
"""return the matching button"""
return self.buttonBox.button(buttonCode)
@staticmethod
......
......@@ -223,7 +223,7 @@ class Url(str, StrMixin):
return False
def connect(self, factory):
"""returns a twisted connector"""
"""return a twisted connector"""
if self.useSocket:
return Internal.reactor.connectUNIX(socketName(), factory, timeout=5)
host = self.host
......
......@@ -4,9 +4,6 @@
SPDX-License-Identifier: GPL-2.0
Read the user manual for a description of the interface to this scoring engine
"""
......@@ -221,7 +218,7 @@ class Meld(TileList, StrMixin):
return tiles
def __setitem__(self, index, value):
"""sets a tile in the meld"""
"""set a tile in the meld"""
raise TypeError
def __delitem__(self, index):
......
......@@ -126,7 +126,7 @@ class ClientMessage(Message):
return self.i18nName.replace(i18nShortcut, '&' + i18nShortcut, 1)
def toolTip(self, button, tile): # pylint: disable=unused-argument
"""returns text and warning flag for button and text for tile for button and text for tile"""
"""return text and warning flag for button and text for tile for button and text for tile"""
txt = 'toolTip is not defined for %s' % self.name
logWarning(txt)
return txt, True, ''
......@@ -328,7 +328,7 @@ class MessageMahJongg(NotifyAtOnceMessage, ServerMessage):
table.claimMahJongg(msg)
def toolTip(self, button, tile): # pylint: disable=unused-argument
"""returns text and warning flag for button and text for tile"""
"""return text and warning flag for button and text for tile"""
return i18n('Press here and you win'), False, ''
def clientAction(self, client, move):
......@@ -797,7 +797,7 @@ class MessageOK(ClientMessage):
shortcut=i18ncE('kajongg game dialog:Key for OK', 'O'))
def toolTip(self, button, tile): # pylint: disable=unused-argument
"""returns text and warning flag for button and text for tile for button and text for tile"""
"""return text and warning flag for button and text for tile for button and text for tile"""
return i18n('Confirm that you saw the message'), False, ''
......@@ -811,7 +811,7 @@ class MessageNoClaim(NotifyAtOnceMessage, ServerMessage):
shortcut=i18ncE('kajongg game dialog:Key for No claim', 'N'))
def toolTip(self, button, tile): # pylint: disable=unused-argument
"""returns text and warning flag for button and text for tile for button and text for tile"""
"""return text and warning flag for button and text for tile for button and text for tile"""
return i18n('You cannot or do not want to claim this tile'), False, ''
@classmethod
......
......@@ -4,9 +4,6 @@
SPDX-License-Identifier: GPL-2.0
Read the user manual for a description of the interface to this scoring engine
"""
......@@ -62,7 +59,7 @@ class Permutations:
@classmethod
def permute(cls, valuesTuple):
"""returns all groupings into melds.
"""return all groupings into melds.
values is a tuple of int, range 1..9"""
assert isinstance(valuesTuple, tuple)
if valuesTuple in cls.permuteCache:
......
......@@ -382,7 +382,7 @@ class Player(StrMixin):
self._hand = None
def __computeHand(self):
"""returns Hand for this player"""
"""return Hand for this player"""
assert not (self._concealedMelds and self._concealedTiles)
melds = list()
melds.extend(str(x) for x in self._exposedMelds)
......@@ -517,7 +517,7 @@ class PlayingPlayer(Player):
self._hand = None
def __possibleChows(self):
"""returns a unique list of lists with possible claimable chow combinations"""
"""return a unique list of lists with possible claimable chow combinations"""
if self.game.lastDiscard is None:
return []
exposedChows = [x for x in self._exposedMelds if x.isChow]
......@@ -529,7 +529,7 @@ class PlayingPlayer(Player):
return within.hasChows(tile)
def __possibleKongs(self):
"""returns a unique list of lists with possible kong combinations"""
"""return a unique list of lists with possible kong combinations"""
kongs = []
if self == self.game.activePlayer:
# declaring a kong
......@@ -550,13 +550,13 @@ class PlayingPlayer(Player):
return kongs
def __maySayChow(self, unusedMove):
"""returns answer arguments for the server if calling chow is possible.
"""return answer arguments for the server if calling chow is possible.
returns the meld to be completed"""
if self == self.game.nextPlayer():
return self.__possibleChows()
def __maySayPung(self, unusedMove):
"""returns answer arguments for the server if calling pung is possible.
"""return answer arguments for the server if calling pung is possible.
returns the meld to be completed"""
lastDiscard = self.game.lastDiscard
if self.game.lastDiscard:
......@@ -565,12 +565,12 @@ class PlayingPlayer(Player):
return MeldList([lastDiscard.pung])
def __maySayKong(self, unusedMove):
"""returns answer arguments for the server if calling or declaring kong is possible.
"""return answer arguments for the server if calling or declaring kong is possible.
returns the meld to be completed or to be declared"""
return self.__possibleKongs()
def __maySayMahjongg(self, move):
"""returns answer arguments for the server if calling or declaring Mah Jongg is possible"""
"""return answer arguments for the server if calling or declaring Mah Jongg is possible"""
game = self.game
if move.message == Message.DeclaredKong:
withDiscard = move.meld[0].concealed
......@@ -591,7 +591,7 @@ class PlayingPlayer(Player):
return MeldList(x for x in hand.melds if not x.isDeclared), withDiscard, hand.lastMeld
def __maySayOriginalCall(self, unusedMove):
"""returns True if Original Call is possible"""
"""return True if Original Call is possible"""
for tileName in sorted(set(self.concealedTiles)):
newHand = self.hand - tileName
if newHand.callingHands:
......
......@@ -5,9 +5,6 @@ Copyright (C) 2008-2016 Wolfgang Rohdewald <wolfgang@rohdewald.de>
SPDX-License-Identifier: GPL-2.0
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
"""
from mi18n import i18n, i18nc
......
Markdown is supported
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