Python: Fix linting issues

The following Flake8 issues were fixed:

* W291
* W504

* F821
* F401
* F541

* E402
* E711
This commit is contained in:
Martin Thoma
2022-03-14 13:13:20 +01:00
parent 8b16a70d32
commit 0ba0307767
16 changed files with 48 additions and 50 deletions

View File

@@ -28,4 +28,4 @@ jobs:
mypy . --exclude 79_Slalom --exclude 27_Civil_War --exclude 38_Fur_Trader --exclude 81_Splat --exclude 09_Battle --exclude 40_Gomoko --exclude 36_Flip_Flop --exclude 43_Hammurabi --exclude 04_Awari --exclude 78_Sine_Wave --exclude 77_Salvo --exclude 34_Digits --exclude 17_Bullfight --exclude 16_Bug
- name: Test with flake8
run: |
flake8 . --ignore E501,W504,W503,F541,E203,W291,E711,F821,F401,E402,E731
flake8 . --ignore E501,W503,E203,E731

View File

@@ -3,7 +3,7 @@ from amazing import build_maze, welcome_header
def test_welcome_header(capsys):
assert welcome_header() == None
assert welcome_header() is None
out, err = capsys.readouterr()
assert out == (
" AMAZING PROGRAM\n"

View File

@@ -112,7 +112,7 @@ def main() -> None:
sea = tuple([0 for _ in range(SEA_WIDTH)] for _ in range(SEA_WIDTH))
setup_ships(sea)
print(
f"""
"""
BATTLE
CREATIVE COMPUTING MORRISTOWN, NEW JERSEY

View File

@@ -133,7 +133,7 @@ def update_game(data, action):
# the new part depends on and doesn't have enough of the part already
overMaxParts = part_type.count < part_count + 1
missingPartDep = (
part_type.depends != None and parts[part_type.depends] == 0
part_type.depends is not None and parts[part_type.depends] == 0
)
if not overMaxParts and not missingPartDep:

View File

@@ -190,20 +190,21 @@ def main():
union_strategy_index = 0
u = 0
u2 = 0
random_nb = 0
while True:
print()
print()
print()
a = int(input("WHICH BATTLE DO YOU WISH TO SIMULATE? "))
if a < 1 or a > 14:
simulated_battle_index = int(input("WHICH BATTLE DO YOU WISH TO SIMULATE? "))
if simulated_battle_index < 1 or simulated_battle_index > 14:
break
if a != 0 or r == 0:
cs = historical_data[a][0]
m1 = historical_data[a][1]
m2 = historical_data[a][2]
c1 = historical_data[a][3]
c2 = historical_data[a][4]
m = historical_data[a][5]
if simulated_battle_index != 0 or random_nb == 0:
cs = historical_data[simulated_battle_index][0]
m1 = historical_data[simulated_battle_index][1]
m2 = historical_data[simulated_battle_index][2]
c1 = historical_data[simulated_battle_index][3]
c2 = historical_data[simulated_battle_index][4]
m = historical_data[simulated_battle_index][5]
u = 0
# Inflation calc
i1 = 10 + (line - w) * 2
@@ -228,7 +229,7 @@ def main():
print()
print(f"THIS IS THE BATTLE OF {cs}")
if xs != "NO":
print("\n".join(battles[a - 1]))
print("\n".join(battles[simulated_battle_index - 1]))
else:
print(cs + " INSTANT REPLAY")
@@ -318,7 +319,7 @@ def main():
print("THE CONFEDERACY HAS SURRENDERED.")
break
# Union strategy is computer chosen
if a == 0:
if simulated_battle_index == 0:
while True:
union_strategy_index = int(input("UNION STRATEGY IS "))
if union_strategy_index > 0 and union_strategy_index < 5:
@@ -326,12 +327,12 @@ def main():
print("ENTER 1, 2, 3, OR 4 (USUALLY PREVIOUS UNION STRATEGY)")
else:
s0 = 0
r = math.random() * 100
random_nb = math.random() * 100
for i in range(1, 5):
s0 += sa[i]
# If actual strategy info is in program data statements
# then r-100 is extra weight given to that strategy.
if r < s0:
if random_nb < s0:
break
union_strategy_index = i
print(union_strategy_index)
@@ -347,7 +348,7 @@ def main():
print("YOUR STRATEGY ? ", end="")
if i == 2:
union_strategy_index = strategy_index
strategy_index = previous_strategy
strategy_index = previous_strategy # noqa: F821
if union_strategy_index != 5:
break
else:
@@ -407,15 +408,15 @@ def main():
w0 += 1
elif u == 1 or (u != 1 and u2 != 1 and c5 + e > c6 + e2):
print("THE UNION WINS " + str(cs))
if a != 0:
if simulated_battle_index != 0:
line += 1
else:
print("THE CONFEDERACY WINS " + str(cs))
if a != 0:
if simulated_battle_index != 0:
w += 1
# Lines 2530 to 2590 from original are unreachable.
if a != 0:
if simulated_battle_index != 0:
t1 += c5 + e
t2 += c6 + e2
p1 += c1

View File

@@ -74,8 +74,8 @@ while play_again:
play_again = m == "5"
if winnings < 0:
print(f"Too bad, you are in the hole. Come again.")
print("Too bad, you are in the hole. Come again.")
elif winnings > 0:
print(f"Congratulations---you came out a winner. Come again.")
print("Congratulations---you came out a winner. Come again.")
else:
print(f"Congratulations---you came out even, not bad for an amateur")
print("Congratulations---you came out even, not bad for an amateur")

View File

@@ -73,7 +73,7 @@ def get_shot_input():
x, y, z = raw_guess.split()
except ValueError:
print("Please enter coordinates separated by spaces")
print(f"Example: 3 2 1")
print("Example: 3 2 1")
continue
try:
x, y, z = (int(num) for num in [x, y, z])

View File

@@ -19,8 +19,6 @@
# more structured style.
#
import random
# global variables
marbles_in_middle = -1
human_marbles = -1

View File

@@ -249,7 +249,7 @@ if __name__ == "__main__":
beaver_price = (
int((0.25 * random.random() + 1.00) * 100 + 0.5) / 100
) # INT((.25*RND(1)+1.00)*10^2+.5)/10^2
if fox_price == None:
if fox_price is None:
# Original Bug? There is no Fox price generated for New York, it will use any previous "D1" price
# So if there was no previous value, make one up
fox_price = (

View File

@@ -1,12 +1,12 @@
import random
from typing import List, Tuple
from typing import Any, List, Tuple
def print_n_whitespaces(n: int) -> None:
print(" " * n, end="")
def print_board():
def print_board(A: List[List[Any]], n):
"""PRINT THE BOARD"""
for i in range(n):
print(" ", end="")
@@ -128,7 +128,7 @@ def main():
and board[X - 1][Y - 1] == 0
):
board[X - 1][Y - 1] = 2
print_board()
print_board(board, n)
break
else:
if board[X - 1][Y - 1] != 0:
@@ -140,11 +140,11 @@ def main():
and board[X - 1][Y - 1] == 0
):
board[X - 1][Y - 1] = 2
print_board()
print_board(board, n)
break
else:
board[X - 1][Y - 1] = 2
print_board()
print_board(board, n)
print()
print("THANKS FOR THE GAME!!")
repeat = input("PLAY AGAIN (1 FOR YES, 0 FOR NO)? ")

View File

@@ -73,16 +73,16 @@ def solve_sex_problem(user_name):
valid, too_much = prompt_too_much_or_too_little()
if valid:
if too_much:
print(f"YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!")
print("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!")
print(f"IF IT BOTHERS YOU, {user_name}, TAKE A COLD SHOWER.")
else:
print(f"WHY ARE YOU HERE IN SUFFERN, {user_name}? YOU SHOULD BE")
print(f"IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME")
print(f"REAL ACTION.")
print("IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME")
print("REAL ACTION.")
return
else:
print(f"DON'T GET ALL SHOOK, {user_name}, JUST ANSWER THE QUESTION")
print(f"WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT?")
print("WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT?")
def solve_money_problem(user_name):
@@ -140,7 +140,7 @@ def ask_question_loop(user_name):
def ask_for_fee(user_name):
print()
print(f"THAT WILL BE $5.00 FOR THE ADVICE, {user_name}.")
print(f"PLEASE LEAVE THE MONEY ON THE TERMINAL.")
print("PLEASE LEAVE THE MONEY ON THE TERMINAL.")
time.sleep(4)
print()
print()

View File

@@ -12,10 +12,10 @@ Ported by Dave LeCompte
# state. This adaptation pulls things apart into phrases, but I have
# left the variables as globals, which makes goes against decades of
# wisdom that global state is bad.
import random
PAGE_WIDTH = 64
import random
# globals
u = 0

View File

@@ -919,7 +919,7 @@ def end_game(won=False, quit=True, enterprise_killed=False):
print(f"IT IS STARDATE {round(t, 1)}")
print(f"THERE WERE {k9} KLINGON BATTLE CRUISERS LEFT AT")
print(f"THE END OF YOUR MISSION.\n\n")
print("THE END OF YOUR MISSION.\n\n")
if b9 == 0:
exit()

View File

@@ -6,7 +6,6 @@ Weapon targeting simulation / 3d trigonometry practice
Ported by Dave LeCompte
"""
import collections
import math
import random
@@ -129,9 +128,9 @@ def do_shot_loop(p1, x, y, z):
print()
print(" * * * HIT * * * TARGET IS NON FUNCTIONAL")
print()
print(f"DISTANCE OF EXPLOSION FROM TARGET WAS {d:.4f} KILOMETERS")
print(f"DISTANCE OF EXPLOSION FROM TARGET WAS {distance:.4f} KILOMETERS")
print()
print(f"MISSION ACCOMPLISHED IN {r} SHOTS.")
print(f"MISSION ACCOMPLISHED IN {shot_count} SHOTS.")
return
else:

View File

@@ -205,13 +205,13 @@ class TicTacToe3D:
return event(i)
m = self.markAndMove(80, 88, 43)
if m != None:
if m is not None:
return m
self.clearStrategyMarks()
m = self.markAndMove(16, 24, 11)
if m != None:
if m is not None:
return m
for k in range(18):
@@ -223,7 +223,7 @@ class TicTacToe3D:
for s in [1, 0]:
for i in range(4 * k, 4 * k + 4):
m = self.moveDiagonals(i, s)
if m != None:
if m is not None:
return m
self.clearStrategyMarks()

View File

@@ -117,13 +117,13 @@ def think(board, g, h, moves):
if g == OccupiedBy.PLAYER:
j = 3 * int((moves - 1) / 3)
if move == j + 1:
if move == j + 1: # noqa: This definitely is a bug!
k = 1
if move == j + 2:
if move == j + 2: # noqa: This definitely is a bug!
k = 2
if move == j + 3:
if move == j + 3: # noqa: This definitely is a bug!
k = 3
return subthink(g, h, j, k)
return subthink(g, h, j, k) # noqa: This definitely is a bug!
def render_board(board, space_mapping):