Skip to content

Commit

Permalink
Upgraded syntax to py3.7+ with pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Dec 15, 2021
1 parent 3c6970c commit 258a4bf
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/asphalt/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def run(configfile, unsafe: bool, loop: Optional[str], service: Optional[str]):
service_config = services[service]
except KeyError:
raise click.ClickException(
'Service {!r} has not been defined'.format(service)) from None
f'Service {service!r} has not been defined') from None
elif len(services) == 1:
service_config = next(iter(services.values()))
elif 'default' in services:
Expand Down
2 changes: 1 addition & 1 deletion src/asphalt/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def add_component(self, alias: str, type: Union[str, type] = None, **config):
if not isinstance(alias, str) or not alias:
raise TypeError('component_alias must be a nonempty string')
if alias in self.child_components:
raise ValueError('there is already a child component named "{}"'.format(alias))
raise ValueError(f'there is already a child component named "{alias}"')

config['type'] = type or alias

Expand Down
4 changes: 2 additions & 2 deletions src/asphalt/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __getattr__(self, name):
if value is not None:
return getattr(ctx, name)

raise AttributeError('no such context variable: {}'.format(name))
raise AttributeError(f'no such context variable: {name}')

@property
def context_chain(self) -> List['Context']:
Expand Down Expand Up @@ -649,6 +649,6 @@ async def teardown_callback(exception: Optional[Exception]):
if iscoroutinefunction(func):
func = async_generator(func)
elif not isasyncgenfunction(func):
raise TypeError('{} must be an async generator function'.format(callable_name(func)))
raise TypeError(f'{callable_name(func)} must be an async generator function')

return wrapper
2 changes: 1 addition & 1 deletion src/asphalt/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async def do_dispatch() -> None:
future.set_result(all_successful)

if not isinstance(event, self.event_class):
raise TypeError('event must be of type {}'.format(qualified_name(self.event_class)))
raise TypeError(f'event must be of type {qualified_name(self.event_class)}')

loop = get_running_loop()
future = loop.create_future()
Expand Down
10 changes: 5 additions & 5 deletions src/asphalt/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def resolve_reference(ref):
obj = import_module(modulename)
except ImportError as e:
raise LookupError(
'error resolving reference {}: could not import module'.format(ref)) from e
f'error resolving reference {ref}: could not import module') from e

try:
for name in rest.split('.'):
obj = getattr(obj, name)

return obj
except AttributeError:
raise LookupError('error resolving reference {}: error looking up object'.format(ref))
raise LookupError(f'error resolving reference {ref}: error looking up object')


def qualified_name(obj) -> str:
Expand All @@ -61,15 +61,15 @@ def qualified_name(obj) -> str:
if obj.__module__ == 'builtins':
return obj.__name__
else:
return '{}.{}'.format(obj.__module__, obj.__qualname__)
return f'{obj.__module__}.{obj.__qualname__}'


def callable_name(func: Callable) -> str:
"""Return the qualified name (e.g. package.module.func) for the given callable."""
if func.__module__ == 'builtins':
return func.__name__
else:
return '{}.{}'.format(func.__module__, func.__qualname__)
return f'{func.__module__}.{func.__qualname__}'


def merge_config(original: Optional[Dict[str, Any]],
Expand Down Expand Up @@ -143,7 +143,7 @@ def resolve(self, obj):

value = self._entrypoints.get(obj)
if value is None:
raise LookupError('no such entry point in {}: {}'.format(self.namespace, obj))
raise LookupError(f'no such entry point in {self.namespace}: {obj}')

if isinstance(value, EntryPoint):
value = self._entrypoints[obj] = value.load()
Expand Down

0 comments on commit 258a4bf

Please sign in to comment.