Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Games
Kajongg
Commits
1aea8814
Commit
1aea8814
authored
Oct 25, 2017
by
Wolfgang Rohdewald
Browse files
pylint simplify "if len(x):"
parent
a403b9b5
Changes
19
Hide whitespace changes
Inline
Side-by-side
src/animation.py
View file @
1aea8814
...
...
@@ -375,7 +375,7 @@ class AnimatedMixin:
if
self
.
name
()
in
Debug
.
animation
:
logDebug
(
'UITile {}: clear activeAnimation[{}]'
.
format
(
self
.
name
(),
animation
.
pName
()))
self
.
setDrawingOrder
()
if
not
len
(
self
.
activeAnimation
)
:
if
not
self
.
activeAnimation
:
self
.
setCacheMode
(
QGraphicsItem
.
DeviceCoordinateCache
)
self
.
update
()
...
...
src/games.py
View file @
1aea8814
...
...
@@ -239,7 +239,7 @@ class Games(QDialog):
self
.
setQuery
()
# just reload entire table
allGames
=
self
.
view
.
selectionModel
().
selectedRows
(
0
)
deleteGames
=
list
(
x
.
data
()
for
x
in
allGames
)
if
len
(
deleteGames
)
==
0
:
if
not
deleteGames
:
# should never happen
logException
(
'delete: 0 rows selected'
)
WarningYesNo
(
...
...
src/hand.py
View file @
1aea8814
...
...
@@ -185,7 +185,7 @@ class Hand(StrMixin):
assert
len
(
tileStrings
)
<
2
,
tileStrings
self
.
__rest
=
TileList
()
if
len
(
tileStrings
)
:
if
tileStrings
:
self
.
__rest
.
extend
(
TileList
(
tileStrings
[
0
][
1
:]))
last
=
self
.
__lastTile
...
...
src/handboard.py
View file @
1aea8814
...
...
@@ -271,7 +271,7 @@ class HandBoard(Board):
match
=
matches
[
0
]
result
[
match
]
=
newPosition
oldTiles
[
match
.
tile
].
remove
(
match
)
if
not
len
(
oldTiles
[
match
.
tile
]
)
:
if
not
oldTiles
[
match
.
tile
]:
del
oldTiles
[
match
.
tile
]
for
newBonusPosition
in
self
.
newBonusPositions
(
list
(
x
for
x
in
tiles
if
x
.
isBonus
),
newPositions
):
...
...
src/humanclient.py
View file @
1aea8814
...
...
@@ -527,12 +527,12 @@ class HumanClient(Client):
# previously selected ruleset
self
.
tables
=
list
(
x
for
x
in
self
.
tables
if
x
.
ruleset
==
self
.
ruleset
)
if
len
(
self
.
tables
)
:
if
self
.
tables
:
self
.
__updateTableList
()
def
remote_newTables
(
self
,
tables
):
"""update table list"""
assert
len
(
tables
)
assert
tables
def
gotRulesets
(
result
):
"""the server sent us the wanted ruleset definitions"""
...
...
src/kajongg.py
View file @
1aea8814
...
...
@@ -56,7 +56,7 @@ def initRulesets():
else
:
matches
=
list
(
x
for
x
in
rulesets
if
Options
.
rulesetName
in
x
)
if
len
(
matches
)
!=
1
:
if
len
(
matches
)
==
0
:
if
not
matches
:
msg
=
'Ruleset %s is unknown'
%
Options
.
rulesetName
else
:
msg
=
'Ruleset %s is ambiguous: %s'
%
(
...
...
src/kajonggtest.py
View file @
1aea8814
...
...
@@ -125,7 +125,7 @@ class Server(StrMixin):
if
len
(
cls
.
servers
)
>=
OPTIONS
.
servers
:
# maybe we can kill a server without jobs?
for
server
in
cls
.
servers
:
if
len
(
server
.
jobs
)
==
0
:
if
not
server
.
jobs
:
server
.
stop
()
break
# we only need to stop one server
else
:
...
...
@@ -193,7 +193,7 @@ class Server(StrMixin):
return
if
job
:
self
.
jobs
.
remove
(
job
)
if
len
(
self
.
jobs
)
==
0
:
if
not
self
.
jobs
:
self
.
servers
.
remove
(
self
)
if
self
.
process
:
try
:
...
...
@@ -211,7 +211,7 @@ class Server(StrMixin):
for
server
in
cls
.
servers
:
for
job
in
server
.
jobs
[:]:
server
.
stop
(
job
)
assert
len
(
server
.
jobs
)
==
0
,
'stopAll expects no server jobs but found {}'
.
format
(
assert
not
server
.
jobs
,
'stopAll expects no server jobs but found {}'
.
format
(
server
.
jobs
)
server
.
stop
()
...
...
@@ -353,7 +353,7 @@ def neutralize(rows):
def
onlyExistingCommits
(
commits
):
"""filter out non-existing commits"""
global
KNOWNCOMMITS
# pylint: disable=global-statement
if
len
(
KNOWNCOMMITS
)
==
0
:
if
not
KNOWNCOMMITS
:
for
branch
in
subprocess
.
check_output
(
b
'git branch'
.
split
()).
decode
().
split
(
'
\n
'
):
if
'detached'
not
in
branch
and
'no branch'
not
in
branch
:
KNOWNCOMMITS
|=
set
(
subprocess
.
check_output
(
...
...
@@ -638,7 +638,7 @@ def improve_options():
wrong
=
False
for
ruleset
in
wantedRulesets
:
matches
=
list
(
x
for
x
in
OPTIONS
.
knownRulesets
if
ruleset
in
x
)
if
len
(
matches
)
==
0
:
if
not
matches
:
print
(
'ruleset'
,
ruleset
,
'is not known'
,
end
=
' '
)
wrong
=
True
elif
len
(
matches
)
>
1
:
...
...
src/mainwindow.py
View file @
1aea8814
...
...
@@ -100,7 +100,7 @@ except ImportError as importError:
NOTFOUND
.
append
(
'Kajongg is not correctly installed: modules: %s'
%
importError
)
if
len
(
NOTFOUND
)
:
if
NOTFOUND
:
logError
(
"
\n
"
.
join
(
" * %s"
%
s
for
s
in
NOTFOUND
),
showStack
=
False
)
sys
.
exit
(
3
)
...
...
src/meld.py
View file @
1aea8814
...
...
@@ -312,9 +312,9 @@ class Meld(TileList, StrMixin):
def
__lt__
(
self
,
other
):
"""used for sorting. Smaller value is shown first."""
if
len
(
other
)
==
0
:
if
not
other
:
return
False
if
len
(
self
)
==
0
:
if
not
self
:
return
True
if
self
.
isDeclared
and
not
other
.
isDeclared
:
return
True
...
...
@@ -427,7 +427,7 @@ class MeldList(list):
return
TileList
(
sum
(
self
,
[]))
def
__str__
(
self
):
if
len
(
self
)
:
if
self
:
return
' '
.
join
(
str
(
x
)
for
x
in
self
)
else
:
return
''
...
...
src/permutations.py
View file @
1aea8814
...
...
@@ -64,7 +64,7 @@ class Permutations:
gTiles
=
list
(
x
for
x
in
self
.
tiles
if
x
.
group
==
group
)
groupVariants
=
self
.
__colorVariants
(
group
,
list
(
x
.
value
for
x
in
gTiles
))
if
len
(
groupVariants
)
:
if
groupVariants
:
variants
.
append
(
groupVariants
)
result
=
[]
for
variant
in
(
sum
(
x
,
[])
for
x
in
itertools
.
product
(
*
variants
)):
...
...
@@ -97,7 +97,7 @@ class Permutations:
rest
=
values
[:]
for
tile
in
meld
:
rest
.
remove
(
tile
)
if
len
(
rest
)
:
if
rest
:
permuteRest
=
cls
.
permute
(
tuple
(
rest
))
for
combi
in
permuteRest
:
result
.
append
(
tuple
(
list
(
appendValue
)
+
list
(
combi
)))
...
...
src/player.py
View file @
1aea8814
...
...
@@ -154,7 +154,7 @@ class Player(StrMixin):
def
clearCache
(
self
):
"""clears the cache with Hands"""
if
Debug
.
hand
and
len
(
self
.
handCache
)
:
if
Debug
.
hand
and
self
.
handCache
:
self
.
game
.
debug
(
'%s: cache hits:%d misses:%d'
%
(
self
,
self
.
cacheHits
,
self
.
cacheMisses
))
...
...
@@ -363,7 +363,7 @@ class Player(StrMixin):
def
addConcealedTiles
(
self
,
tiles
,
animated
=
False
):
# pylint: disable=unused-argument
"""add to my tiles"""
assert
len
(
tiles
)
assert
tiles
for
tile
in
tiles
:
if
tile
.
isBonus
:
self
.
_bonusTiles
.
append
(
tile
)
...
...
src/playerlist.py
View file @
1aea8814
...
...
@@ -75,7 +75,7 @@ class PlayerList(QDialog):
@
staticmethod
def
sortKey
(
text
):
"""display order in Table"""
if
len
(
text
)
==
0
:
if
not
text
:
return
'zzzzzzzzzzzz'
else
:
return
text
.
upper
()
...
...
@@ -131,20 +131,20 @@ class PlayerList(QDialog):
self
.
updateTable
(
data
=
self
.
_data
,
currentName
=
''
)
for
row
in
range
(
len
(
self
.
_data
)):
item
=
self
.
table
.
item
(
row
,
0
)
if
len
(
item
.
text
()
)
==
0
:
if
not
item
.
text
():
self
.
table
.
editItem
(
item
)
def
delete
(
self
):
"""delete selected entries"""
items
=
self
.
table
.
selectedItems
()
currentRow
=
self
.
table
.
currentRow
()
if
len
(
items
)
:
if
items
:
name
=
items
[
0
].
text
()
playerId
=
self
.
_data
[
name
]
query
=
Query
(
"select 1 from game where p0=? or p1=? or p2=? or p3=?"
,
(
playerId
,
)
*
4
)
if
len
(
query
.
records
)
:
if
query
.
records
:
Sorry
(
i18n
(
'This player cannot be deleted. There are games associated with %1.'
,
name
))
return
...
...
src/rule.py
View file @
1aea8814
...
...
@@ -425,7 +425,7 @@ into a situation where you have to pay a penalty"""))
return
else
:
query
=
Query
(
"select id,hash,name,description from ruleset where hash=?"
,
(
self
.
name
,))
if
len
(
query
.
records
)
:
if
query
.
records
:
(
self
.
rulesetId
,
self
.
__hash
,
self
.
name
,
self
.
description
)
=
query
.
records
[
0
]
else
:
...
...
src/rulecode.py
View file @
1aea8814
...
...
@@ -1179,7 +1179,7 @@ class ThirteenOrphans(MJRule):
return
set
()
handTiles
=
set
(
x
.
exposed
for
x
in
hand
.
tiles
)
missing
=
elements
.
majors
-
handTiles
if
len
(
missing
)
==
0
:
if
not
missing
:
# if all 13 tiles are there, we need any one of them:
return
elements
.
majors
else
:
...
...
src/scoring.py
View file @
1aea8814
...
...
@@ -84,7 +84,7 @@ class SelectPlayers(SelectRuleset):
query
=
Query
(
"select p0,p1,p2,p3 from game where seed is null and game.id = (select max(id) from game)"
)
if
len
(
query
.
records
)
:
if
query
.
records
:
with
BlockSignals
(
self
.
nameWidgets
):
for
cbName
,
playerId
in
zip
(
self
.
nameWidgets
,
query
.
records
[
0
]):
try
:
...
...
src/scoringdialog.py
View file @
1aea8814
...
...
@@ -1206,7 +1206,7 @@ class ScoringDialog(QWidget):
lastTile
=
Internal
.
scene
.
computeLastTile
()
winnerMelds
=
[
m
for
m
in
self
.
game
.
winner
.
hand
.
melds
if
len
(
m
)
<
4
and
lastTile
in
m
]
assert
len
(
winnerMelds
)
,
'lastTile %s missing in %s'
%
(
assert
winnerMelds
,
'lastTile %s missing in %s'
%
(
lastTile
,
self
.
game
.
winner
.
hand
.
melds
)
if
len
(
winnerMelds
)
==
1
:
self
.
cbLastMeld
.
addItem
(
QIcon
(),
''
,
str
(
winnerMelds
[
0
]))
...
...
src/server.py
View file @
1aea8814
...
...
@@ -114,7 +114,7 @@ class DBPasswordChecker:
pass
query
=
Query
(
'select id, password from player where name=?'
,
(
cred
.
username
,))
if
not
len
(
query
.
records
)
:
if
not
query
.
records
:
template
=
'Wrong username: %1'
if
Debug
.
connections
:
logDebug
(
i18n
(
template
,
cred
.
username
))
...
...
@@ -211,7 +211,7 @@ class MJServer:
if
tables
is
None
:
tables
=
list
(
x
for
x
in
self
.
tables
.
values
()
if
not
x
.
running
and
(
not
x
.
suspendedAt
or
x
.
hasName
(
user
.
name
)))
if
len
(
tables
)
:
if
tables
:
data
=
list
(
x
.
asSimpleList
()
for
x
in
tables
)
if
Debug
.
table
:
logDebug
(
...
...
src/uitile.py
View file @
1aea8814
...
...
@@ -426,7 +426,7 @@ class UIMeld(list):
self
.
extend
(
newContent
)
elif
isinstance
(
newContent
,
UITile
):
self
.
append
(
newContent
)
assert
len
(
self
)
,
newContent
assert
self
,
newContent
@
property
def
meld
(
self
):
...
...
src/wind.py
View file @
1aea8814
...
...
@@ -43,7 +43,7 @@ class Wind:
assert
cls
is
Wind
,
'{}({}) is illegal'
.
format
(
cls
.
__name__
,
windIdent
)
windIdx
=
'eswn'
.
index
(
windIdent
.
lower
())
return
Wind
.
all
[
windIdx
]
assert
len
(
args
)
==
0
and
cls
is
not
Wind
,
'Wind() must have exactly one argument'
assert
not
args
and
cls
is
not
Wind
,
'Wind() must have exactly one argument'
for
result
in
Wind
.
all
:
if
isinstance
(
result
,
cls
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment