From 0d219f47670e58c0a3cf73dcb07bb3cf08071a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Sun, 6 Sep 2020 22:50:00 +0700 Subject: [PATCH] Utilize f-strings --- axuy/control.py | 13 ++++++------- axuy/display.py | 12 +++++------- axuy/peer.py | 10 +++++----- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/axuy/control.py b/axuy/control.py index ba9a09d..3206163 100644 --- a/axuy/control.py +++ b/axuy/control.py @@ -31,7 +31,7 @@ from .display import DispConfig, Display CONTROL_ALIASES = (('Move left', 'left'), ('Move right', 'right'), ('Move forward', 'forward'), ('Move backward', 'backward'), ('Primary', '1st'), ('Secondary', '2nd')) -MOUSE_PATTERN = 'MOUSE_BUTTON_[1-{}]'.format(glfw.MOUSE_BUTTON_LAST + 1) +MOUSE_PATTERN = f'MOUSE_BUTTON_[1-{glfw.MOUSE_BUTTON_LAST+1}]' INVALID_CONTROL_ERR = '{}: {} is not recognized as a valid control key' GLFW_VER_WARN = 'Your GLFW version appear to be lower than 3.3, '\ 'which might cause stuttering camera rotation.' @@ -55,21 +55,20 @@ class CtlConfig(DispConfig): DispConfig.__init__(self) self.options.add_argument( '--mouse-speed', type=float, dest='mouspeed', - help='camera rotational speed (fallback: {:.1f})'.format( - self.__mouspeed)) + help=f'camera rotational speed (fallback: {self._mouspeed:.1f})') self.options.add_argument( '--zoom-speed', type=float, dest='zmspeed', - help='zoom speed (fallback: {:.1f})'.format(self.zmspeed)) + help=f'zoom speed (fallback: {self.zmspeed:.1f})') @property def mouspeed(self) -> float: """Relative mouse speed.""" # Standard to radians per inch for a 800 DPI mouse, at FOV of 60 - return self.__mouspeed / 800 + return self._mouspeed / 800 @mouspeed.setter def mouspeed(self, value: float) -> None: - self.__mouspeed = value + self._mouspeed = value def fallback(self) -> None: """Parse fallback configurations.""" @@ -83,7 +82,7 @@ class CtlConfig(DispConfig): self.mouse[alias] = getattr(glfw, i.upper()) continue try: - self.key[alias] = getattr(glfw, 'KEY_{}'.format(i.upper())) + self.key[alias] = getattr(glfw, f'KEY_{i.upper()}') except AttributeError: raise ValueError(INVALID_CONTROL_ERR.format(cmd, i)) diff --git a/axuy/display.py b/axuy/display.py index a6c23f0..00566a9 100644 --- a/axuy/display.py +++ b/axuy/display.py @@ -73,21 +73,19 @@ class DispConfig(PeerConfig): def __init__(self) -> None: PeerConfig.__init__(self) + x, y = self.size self.options.add_argument( '--size', type=int, nargs=2, metavar=('X', 'Y'), - help='the desired screen size (fallback: {}x{})'.format( - *self.size)) + help=f'the desired screen size (fallback: {x}x{y})') self.options.add_argument( '--vsync', action='store_true', default=None, - help='enable vertical synchronization (fallback: {})'.format( - self.vsync)) + help=f'enable vertical synchronization (fallback: {self.vsync})') self.options.add_argument( '--no-vsync', action='store_false', dest='vsync', help='disable vertical synchronization') self.options.add_argument( '--fov', type=float, metavar='DEGREES', - help='horizontal field of view (fallback: {:})'.format( - round(self.fov))) + help=f'horizontal field of view (fallback: {round(self.fov)})') @property def fov(self) -> float: @@ -328,7 +326,7 @@ class Display(Peer): """Pretty string for displaying average FPS.""" # Average over 5 seconds, like how glxgears do it, but less efficient while len(self.fpses) > mean(self.fpses) * 5 > 0: self.fpses.pop() - return '{} fps'.format(round(mean(self.fpses))) + return f'{round(mean(self.fpses))} fps' def get_time(self) -> float: """Return the current time in seconds.""" diff --git a/axuy/peer.py b/axuy/peer.py index c907e6e..e87c012 100644 --- a/axuy/peer.py +++ b/axuy/peer.py @@ -72,21 +72,21 @@ class PeerConfig: self.options = ArgumentParser(usage='%(prog)s [options]', formatter_class=RawTextHelpFormatter) self.options.add_argument('-v', '--version', action='version', - version='Axuy {}'.format(__version__)) + version=f'Axuy {__version__}') self.options.add_argument( '--write-config', nargs='?', const=stdout, type=FileType('w'), metavar='PATH', dest='cfgout', help='write default config to PATH (fallback: stdout) and exit') self.options.add_argument( '-c', '--config', metavar='PATH', - help='location of the configuration file (fallback: {})'.format( - pathsep.join(filenames))) + help=('location of the configuration file' + f' (fallback: {pathsep.join(filenames)})')) self.options.add_argument( '--host', - help='host to bind this peer to (fallback: {})'.format(self.host)) + help=f'host to bind this peer to (fallback: {self.host})') self.options.add_argument( '-p', '--port', type=int, - help='port to bind this peer to (fallback: {})'.format(self.port)) + help=f'port to bind this peer to (fallback: {self.port})') self.options.add_argument( '-s', '--seeder', metavar='ADDRESS', help='address of the peer that created the map')