Skip to content

Commit

Permalink
f-strings!1!!
Browse files Browse the repository at this point in the history
  • Loading branch information
obestwalter committed Mar 31, 2017
1 parent cba2c02 commit fa55fb5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
8 changes: 4 additions & 4 deletions mau_mau/concepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def __init__(self, table):

def __repr__(self):
name = self.__class__.__name__
return "%s(%s)" % (name, self.table)
return f"{name}({self.table})"

def next_turn(self):
self.turns += 1
self.player = self.player.nextPlayer
log.debug("%s turn %s %s" % ("-" * 20, self.turns, "-" * 20))
log.debug(f"{'-' * 20 } turn {self.turns} {'-' * 20 }")
log.debug("upcard: %s", self.table.upcard)
log.debug("%s is up", self.player)
log.debug(f"{self.player} is up")
return self.player

@property
Expand Down Expand Up @@ -54,7 +54,7 @@ def __repr__(self):
'Stock([1, 2, 3])'
"""
name = self.__class__.__name__
return "%s(%s)" % (name, self.cards)
return f"{name}({self.cards})"

def __len__(self):
"""Object has a length that is the number of cards contained in it.
Expand Down
4 changes: 4 additions & 0 deletions mau_mau/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ class DECK:
JACK = 'Jack'
VALUES = [SEVEN, EIGHT, 9, 10, JACK, 'Queen', 'King', 'Ace']
SUITS = ['♦', '♥', '♠', '♣']


class LOG:
FMT = '%(name)-20s%(lineno)-3s %(funcName)-17s: %(message)s'.format()
4 changes: 2 additions & 2 deletions mau_mau/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):

def __repr__(self):
name = self.__class__.__name__
return "%s(%s, %s)" % (name, self.rules, self.players)
return f"{name}({self.rules}, {self.players})"

def join(self, players):
"""Players join the table and therefore learn who comes next
Expand Down Expand Up @@ -68,4 +68,4 @@ def __init__(self, value, suit):

def __repr__(self):
name = self.__class__.__name__
return "%s('%s', '%s')" % (name, self.value, self.suit)
return f"{name}('{self.value}', '{self.suit}')"
4 changes: 2 additions & 2 deletions mau_mau/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, card, ruleClass):

def __repr__(self):
name = self.__class__.__name__
return "%s on %s" % (name, self.card)
return f"{name} on {self.card}"

def find_playable_cards(self, cards):
return self.rules.find_playable_cards(self.card, cards)
Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__(self, cardsPerPlayer=5):

def __repr__(self):
name = self.__class__.__name__
return "%s(%s)" % (name, self.cardsPerPlayer)
return f"{name}({self.cardsPerPlayer})"

@classmethod
def get_rule(cls, card):
Expand Down
6 changes: 3 additions & 3 deletions mau_mau/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def wantedSuit(self):
@classmethod
def get_valid_choice(cls, choices, msg):
def visualize(elems):
c = ["%s -> %s" % (i, c) for i, c in enumerate(elems, 1)]
c = [f"{i} -> {c}" for i, c in enumerate(elems, 1)]
return " | ".join(c)

while True:
idx = input("%s.\n%s | " % (msg, visualize(choices)))
idx = input(f"{msg}.\n{visualize(choices)} | ")
try:
return choices[int(idx) - 1]

except (IndexError, ValueError):
log.warning("'%s' is not a valid choice", idx)
log.warning(f"'{idx}' is not a valid choice")
6 changes: 3 additions & 3 deletions mau_mau/subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _create_real_players(cls, seed):
:type seed: int or list of str
"""
if not isinstance(seed, collections.Iterable):
return [Player("Player %s" % (n)) for n in range(1, seed + 1)]
return [Player(f"Player {n}") for n in range(1, seed + 1)]

return [Player(p, HumanStrategy if p == 'human' else BasicStrategy)
for p in seed]
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, name, strategyClass=BasicStrategy):

def __repr__(self):
name = self.__class__.__name__
return "%s('%s', %s)" % (name, self.name, self.hand)
return f"{name}('self.name', {self.hand})"

def __eq__(self, other):
return self.name == other.name
Expand All @@ -85,7 +85,7 @@ def draw(self, table, amount=1):
table.replenish_stock()
card = table.stock.fetch()
self.hand.put(card)
log.debug("%s <- %s" % (self.name, card))
log.debug(f"{self.name} <- {card}")

def put(self, table, card, strategy):
log.debug("play %s", card)
Expand Down
8 changes: 5 additions & 3 deletions tools/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

import os

from mau_mau.statistics import winner_distribution
from mau_mau.statistics import Statistics

userPath = os.path.expanduser('~')
pmPath = os.path.join(userPath, '.opt/pyvmmonitor/public_api')
print("looking for monitor at '%s'" % (pmPath))
print(f"looking for monitor at '{pmPath}'")
sys.path.append(pmPath)


import pyvmmonitor


@pyvmmonitor.profile_method
def profile_stuff():
winner_distribution()
Statistics().winners()

0 comments on commit fa55fb5

Please sign in to comment.