Skip to content
This repository has been archived by the owner on Jan 25, 2025. It is now read-only.

Replace all "format"s with f-strings #26

Merged
merged 3 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/26.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade all codebase to use format-strings
8 changes: 4 additions & 4 deletions src/travertino/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __hash__(self):
return hash(('RGBA-color', self.r, self.g, self.b, self.a))

def __repr__(self):
return "rgba({}, {}, {}, {})".format(self.r, self.g, self.b, self.a)
return f"rgba({self.r}, {self.g}, {self.b}, {self.a})"

@classmethod
def _validate_rgb(cls, content_name, value):
Expand All @@ -71,7 +71,7 @@ def __init__(self, r, g, b):
super().__init__(r, g, b, 1.0)

def __repr__(self):
return "rgb({}, {}, {})".format(self.r, self.g, self.b)
return f"rgb({self.r}, {self.g}, {self.b})"


class hsla(Color):
Expand All @@ -90,7 +90,7 @@ def __hash__(self):
return hash(('HSLA-color', self.h, self.s, self.l, self.a))

def __repr__(self):
return "hsla({}, {}, {}, {})".format(self.h, self.s, self.l, self.a)
return f"hsla({self.h}, {self.s}, {self.l}, {self.a})"

@property
def rgba(self):
Expand Down Expand Up @@ -126,7 +126,7 @@ def __init__(self, h, s, l):
super().__init__(h, s, l, 1.0)

def __repr__(self):
return "hsl({}, {}, {})".format(self.h, self.s, self.l)
return f"hsl({self.h}, {self.s}, {self.l})"


def color(value):
Expand Down
6 changes: 3 additions & 3 deletions src/travertino/declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def validate(self, value):
if value == const:
return const

raise ValueError("'{0}' is not a valid initial value".format(value))
raise ValueError(f"'{value}' is not a valid initial value")

def __str__(self):
return ", ".join(self._options)
Expand Down Expand Up @@ -158,7 +158,7 @@ def __str__(self):
pass

return "; ".join(
"%s: %s" % (name, value)
f"{name}: {value}"
for name, value in sorted(non_default)
)

Expand All @@ -168,7 +168,7 @@ def validated_property(cls, name, choices, initial=None):
try:
initial = choices.validate(initial)
except ValueError:
raise ValueError("Invalid initial value '{}' for property '{}'".format(initial, name))
raise ValueError(f"Invalid initial value '{initial}' for property '{name}'")

def getter(self):
return getattr(self, '_%s' % name, initial)
Expand Down
14 changes: 7 additions & 7 deletions src/travertino/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def __init__(self, family, size, style=NORMAL, variant=NORMAL, weight=NORMAL):
if size.strip().endswith('pt'):
self.size = int(size[:-2])
else:
raise ValueError("Invalid font size {!r}".format(size))
raise ValueError(f"Invalid font size {size!r}")
except Exception:
raise ValueError("Invalid font size {!r}".format(size))
raise ValueError(f"Invalid font size {size!r}")
self.style = style if style in FONT_STYLES else NORMAL
self.variant = variant if variant in FONT_VARIANTS else NORMAL
self.weight = weight if weight in FONT_WEIGHTS else NORMAL
Expand All @@ -40,7 +40,7 @@ def __repr__(self):
'' if self.style is NORMAL else (self.style + ' '),
'' if self.variant is NORMAL else (self.variant + ' '),
'' if self.weight is NORMAL else (self.weight + ' '),
'system default size' if self.size == SYSTEM_DEFAULT_FONT_SIZE else '{}pt'.format(self.size),
'system default size' if self.size == SYSTEM_DEFAULT_FONT_SIZE else f'{self.size}pt',
self.family
)

Expand Down Expand Up @@ -120,17 +120,17 @@ def font(value):
weight = NORMAL
elif part in FONT_STYLES:
if style is not None:
raise ValueError("Invalid font declaration '{}'".format(value))
raise ValueError(f"Invalid font declaration '{value}'")
style = part
elif part in FONT_VARIANTS:
if variant is not None:
raise ValueError("Invalid font declaration '{}'".format(value))
raise ValueError(f"Invalid font declaration '{value}'")
if style is None:
style = NORMAL
variant = part
elif part in FONT_WEIGHTS:
if weight is not None:
raise ValueError("Invalid font declaration '{}'".format(value))
raise ValueError(f"Invalid font declaration '{value}'")
if style is None:
style = NORMAL
if variant is None:
Expand All @@ -143,7 +143,7 @@ def font(value):
else:
size = int(part)
except ValueError:
raise ValueError("Invalid size in font declaration '{}'".format(value))
raise ValueError(f"Invalid size in font declaration '{value}'")

if parts[0] == 'pt':
parts.pop(0)
Expand Down
1 change: 0 additions & 1 deletion src/travertino/layout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Viewport:
"""
A viewport is a description of surface onto which content will be
Expand Down
1 change: 1 addition & 0 deletions src/travertino/node.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

class Node:
def __init__(self, style, applicator=None, children=None):
self.applicator = applicator
Expand Down
5 changes: 2 additions & 3 deletions src/travertino/size.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

class at_least:
"An annotation to wrap around a value to describe that it is a minimum bound"
def __init__(self, value):
self.value = value

def __repr__(self):
return 'at least {0}'.format(self.value)
return f'at least {self.value}'

def __eq__(self, other):
try:
Expand All @@ -29,7 +28,7 @@ def __init__(self, width=None, height=None, ratio=None, layout=None):
self._ratio = None

def __repr__(self):
return '({}, {})'.format(self.width, self.height)
return f'({self.width}, {self.height})'

@property
def width(self):
Expand Down