Skip to content

Commit ccf7c19

Browse files
committed
-
1 parent 797d31b commit ccf7c19

File tree

31 files changed

+105
-109
lines changed

31 files changed

+105
-109
lines changed

python_toolbox/address_tools/object_to_string.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def get_address(obj, shorten=False, root=None, namespace={}):
140140
# We'll probably have to do some kind of search.
141141

142142
if not (isinstance(obj, types.ModuleType) or hasattr(obj, '__module__')):
143-
raise TypeError("`%s` is not a module, nor does it have a "
144-
"`.__module__` attribute, therefore we can't get its "
145-
"address." % (obj,))
143+
raise TypeError(f"`{obj}` is not a module, nor does it have a "
144+
f"`.__module__` attribute, therefore we can't get its "
145+
f"address.")
146146

147147
if isinstance(obj, types.ModuleType):
148148
address = obj.__name__

python_toolbox/caching/cached_property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ def inner(same_method_function, self_obj, *args, **kwargs):
7777

7878

7979
def __repr__(self):
80-
return '<%s: %s>' % (type(self).__name__, self.our_name or self.getter)
80+
return f'<{type(self).__name__}: {self.our_name or self.getter}>'

python_toolbox/combi/perming/comb_space.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ def __repr__(self):
4949
return '<%s: %s%s>%s' % (
5050
type(self).__name__,
5151
sequence_repr,
52-
(', n_elements=%s' % (self.n_elements,)) if self.is_partial
53-
else '',
54-
('[%s:%s]' % (self.slice_.start, self.slice_.stop)) if
52+
(f', n_elements={self.n_elements}') if self.is_partial else '',
53+
f'[{self.slice_.start}:{self.slice_.stop}]' if
5554
self.is_sliced else ''
5655
)
5756

python_toolbox/combi/perming/perm_space.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,11 @@ def __repr__(self):
521521
type(self).__name__,
522522
domain_snippet,
523523
sequence_repr,
524-
(', n_elements=%s' % (self.n_elements,)) if self.is_partial
525-
else '',
524+
(f', n_elements={self.n_elements}') if self.is_partial else '',
526525
', is_combination=True' if self.is_combination else '',
527-
(', fixed_map=%s' % (fixed_map_repr,)) if self.is_fixed else '',
528-
(', degrees=%s' % (self.degrees,)) if self.is_degreed else '',
529-
(', perm_type=%s' % (self.perm_type.__name__,)) if self.is_typed
526+
(f', fixed_map={fixed_map_repr}' if self.is_fixed else '',
527+
(f', degrees={self.degrees}') if self.is_degreed else '',
528+
(f', perm_type={self.perm_type.__name__}') if self.is_typed
530529
else '',
531530
('[%s:%s]' % (self.slice_.start, self.slice_.stop)) if
532531
self.is_sliced else ''

python_toolbox/context_management/context_manager_type.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,25 @@ def __new__(mcls, name, bases, namespace):
9696

9797
assert '__enter__' in namespace
9898

99-
raise Exception("The %s class defines an `__enter__` method, "
100-
"but not an `__exit__` method; we cannot use "
101-
"the `__exit__` method of its base context "
102-
"manager class because it uses the "
103-
"`manage_context` generator function." %
104-
result_class)
99+
raise Exception(
100+
f"The {result_class} class defines an `__enter__` method, "
101+
f"but not an `__exit__` method; we cannot use the "
102+
f"`__exit__` method of its base context manager class "
103+
f"because it uses the `manage_context` generator function."
104+
)
105105

106106

107107
if our_enter_uses_manage_context and not \
108108
our_exit_uses_manage_context:
109109

110110
assert '__exit__' in namespace
111111

112-
raise Exception("The %s class defines an `__exit__` method, "
113-
"but not an `__enter__` method; we cannot use "
114-
"the `__enter__` method of its base context "
115-
"manager class because it uses the "
116-
"`manage_context` generator function." %
117-
result_class)
112+
raise Exception(
113+
f"The {result_class} class defines an `__exit__` method, "
114+
f"but not an `__enter__` method; we cannot use the "
115+
f"`__enter__` method of its base context manager class "
116+
f"because it uses the `manage_context` generator function."
117+
)
118118

119119
return result_class
120120

python_toolbox/cute_profile/profile_handling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def __call__(self, profile):
2929
def handle(self):
3030
pass
3131

32-
make_file_name = lambda self: ('%s.profile' %
33-
datetime_module.datetime.now()).replace(':', '.')
32+
make_file_name = lambda self: (
33+
f'{datetime_module.datetime.now()}.profile').replace(':', '.')
3434

3535

3636

python_toolbox/cute_testing.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def manage_context(self):
7373
if self.exception_type is not type(exception):
7474
assert issubclass(type(exception), self.exception_type)
7575
raise Failure(
76-
"The exception `%s` was raised, and it *is* an "
77-
"instance of the `%s` we were expecting; but its type "
78-
"is not `%s`, it's `%s`, which is a subclass of `%s`, "
79-
"but you specified `assert_exact_type=True`, so "
76+
"The exception %s was raised, and it *is* an "
77+
"instance of the %s we were expecting; but its type "
78+
"is not %s, it's %s, which is a subclass of %s, "
79+
"and you specified `assert_exact_type=True`, so "
8080
"subclasses aren't acceptable." % (repr(exception),
8181
self.exception_type.__name__,
8282
self.exception_type.__name__, type(exception).__name__,
@@ -87,24 +87,24 @@ def manage_context(self):
8787
if isinstance(self.text, str):
8888
if self.text not in message:
8989
raise Failure(
90-
"A `%s` was raised but %s wasn't in its message." %
91-
(self.exception_type.__name__, repr(self.text))
90+
f"A {self.exception_type.__name__} was raised "
91+
f"but {repr(self.text)} wasn't in its message."
9292
)
9393
else:
9494
# It's a regex pattern
9595
if not self.text.match(message):
9696
raise Failure(
97-
"A `%s` was raised but it didn't match the given "
98-
"regex." % self.exception_type.__name__
97+
f"A {self.exception_type.__name__} was raised "
98+
f"but it didn't match the given regex."
9999
)
100100
except BaseException as different_exception:
101101
raise Failure(
102-
"%s was excpected, but a different exception %s was raised "
103-
"instead." % (self.exception_type.__name__,
104-
type(different_exception).__name__)
102+
f"{self.exception_type.__name__} was excpected, but a "
103+
f"different exception {type(different_exception).__name__} "
104+
f"was raised instead."
105105
)
106106
else:
107-
raise Failure("%s wasn't raised." % self.exception_type.__name__)
107+
raise Failure(f"{self.exception_type.__name__} wasn't raised.")
108108

109109

110110
def assert_same_signature(*callables):

python_toolbox/decorator_tools.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ def inner(*args, **kwargs):
5252
function = args[0]
5353
function_name = function.__name__
5454
decorator_builder_name = decorator_builder.__name__
55-
raise TypeError('It seems that you forgot to add parentheses '
56-
'after `@%s` when decorating the `%s` '
57-
'function.' % (decorator_builder_name,
58-
function_name))
55+
raise TypeError(
56+
f'It seems that you forgot to add parentheses after '
57+
f'@{decorator_builder_name} when decorating the
58+
f'{function_name} function.'
59+
)
5960
else:
6061
return decorator_builder(*args, **kwargs)
6162

python_toolbox/dict_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ def reverse(d):
164164
for key, value in d.items():
165165
if value in new_d:
166166
raise Exception(
167-
"Value %s appeared twice! Once with a key of %s and then "
168-
"again with a key of %s. This function is intended only for "
169-
"dicts with distinct values." % (value, key, new_d[value])
167+
f"Value {value} appeared twice! Once with a key of {key} and "
168+
f"then again with a key of {new_d[value]}. This function is "
169+
f"intended only for dicts with distinct values."
170170
)
171171
new_d[value] = key
172172
return new_d

python_toolbox/file_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ def atomic_create(path, binary=False):
163163
'''
164164
path = pathlib.Path(path)
165165
if path.exists():
166-
raise Exception("There's already a file called %s" % path)
167-
desired_temp_file_path = path.parent / ('._%s.tmp' % path.stem)
166+
raise FileExistsError(f"There's already a file called {path}")
167+
desired_temp_file_path = path.parent / f'._{path.stem}.tmp'
168168
try:
169169
with create_file_renaming_if_taken(desired_temp_file_path,
170170
'xb' if binary else 'x') as temp_file:
@@ -174,7 +174,7 @@ def atomic_create(path, binary=False):
174174
# This part runs only if there was no exception when writing to the
175175
# file:
176176
if path.exists():
177-
raise Exception("There's already a file called %s" % path)
177+
raise FileExistsError(f"There's already a file called {path}")
178178
actual_temp_file_path.rename(path)
179179
assert path.exists()
180180

0 commit comments

Comments
 (0)