Python: Add type annotations to all 'print' functions (#662)

* Add test to superstartrek and fixes several issues in superstartrek - I probably introduced them 🙈
* Mastermind type annotations
This commit is contained in:
Martin Thoma
2022-03-21 10:41:14 +01:00
committed by GitHub
parent c444da93c0
commit 1b1d50986b
50 changed files with 241 additions and 172 deletions

View File

@@ -2,16 +2,16 @@ import random
import time
def print_n_whitespaces(n: int):
def print_n_whitespaces(n: int) -> None:
print(" " * n, end="")
def print_n_newlines(n: int):
def print_n_newlines(n: int) -> None:
for _ in range(n):
print()
def print_feelers(n_feelers, is_player=True):
def print_feelers(n_feelers, is_player: bool = True) -> None:
for _ in range(4):
print_n_whitespaces(10)
for _ in range(n_feelers):
@@ -19,7 +19,7 @@ def print_feelers(n_feelers, is_player=True):
print()
def print_head():
def print_head() -> None:
print(" HHHHHHH")
print(" H H")
print(" H O O H")
@@ -28,12 +28,12 @@ def print_head():
print(" HHHHHHH")
def print_neck():
def print_neck() -> None:
print(" N N")
print(" N N")
def print_body(has_tail=False):
def print_body(has_tail: bool = False) -> None:
print(" BBBBBBBBBBBB")
print(" B B")
print(" B B")
@@ -41,7 +41,7 @@ def print_body(has_tail=False):
print(" BBBBBBBBBBBB")
def print_legs(n_legs):
def print_legs(n_legs: int) -> None:
for _ in range(2):
print_n_whitespaces(5)
for _ in range(n_legs):

View File

@@ -38,7 +38,7 @@ def main(states, data) -> None:
Bodypart = namedtuple("Bodypart", ["name", "count", "depends"])
def print_start(_):
def print_start(_) -> str:
"""
Prints start message
"""
@@ -64,7 +64,7 @@ def control_start(cmd):
return action
def print_instructions(data):
def print_instructions(data) -> str:
"""
Prints game instructions
"""
@@ -171,7 +171,7 @@ def get_finished(data):
return finished
def print_game(data):
def print_game(data) -> str:
"""
Displays the results of the game turn
"""
@@ -222,7 +222,7 @@ def print_game(data):
return input("DO YOU WANT THE PICTURES? ") if len(data["logs"]) else "n"
def print_pictures(data):
def print_pictures(data) -> None:
"""
Displays what the bugs look like for each player
"""
@@ -272,7 +272,7 @@ def control_game(cmd):
return action
def print_winner(data):
def print_winner(data) -> None:
"""
Displays the winning message
"""
@@ -288,7 +288,7 @@ def exit_game(_):
return "exit"
def print_centered(msg, width=PAGE_WIDTH):
def print_centered(msg, width=PAGE_WIDTH) -> None:
"""
Prints given message centered to given width
"""
@@ -296,7 +296,7 @@ def print_centered(msg, width=PAGE_WIDTH):
print(spaces + msg)
def print_table(rows):
def print_table(rows) -> None:
for row in rows:
print(*row, sep="\t")