diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 10a0e97e..a50c2ec3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,12 +19,12 @@ repos: - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.23.3 + rev: 0.26.3 hooks: - id: check-github-workflows - repo: https://github.com/executablebooks/mdformat - rev: 0.7.16 + rev: 0.7.17 hooks: - id: mdformat @@ -34,7 +34,7 @@ repos: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.281 + rev: v0.0.287 hooks: - id: ruff args: ["--fix"] diff --git a/traitlets/config/application.py b/traitlets/config/application.py index e5967306..af8fe536 100644 --- a/traitlets/config/application.py +++ b/traitlets/config/application.py @@ -503,12 +503,7 @@ def start_show_config(self): for traitname in sorted(class_config): value = class_config[traitname] - print( - " .{} = {}".format( - traitname, - pprint.pformat(value, **pformat_kwargs), - ) - ) + print(f" .{traitname} = {pprint.pformat(value, **pformat_kwargs)}") def print_alias_help(self): """Print the alias parts of the help.""" diff --git a/traitlets/config/configurable.py b/traitlets/config/configurable.py index 41f1f8cf..c3b2ed16 100644 --- a/traitlets/config/configurable.py +++ b/traitlets/config/configurable.py @@ -560,8 +560,8 @@ def instance(cls, *args, **kwargs): return cls._instance else: raise MultipleInstanceError( - "An incompatible sibling of '{}' is already instantiated" - " as singleton: {}".format(cls.__name__, type(cls._instance).__name__) + f"An incompatible sibling of '{cls.__name__}' is already instantiated" + f" as singleton: {type(cls._instance).__name__}" ) @classmethod diff --git a/traitlets/config/loader.py b/traitlets/config/loader.py index e9de7f81..a9136dc3 100644 --- a/traitlets/config/loader.py +++ b/traitlets/config/loader.py @@ -348,7 +348,7 @@ def __setitem__(self, key, value): if not isinstance(value, Config): raise ValueError( "values whose keys begin with an uppercase " - "char must be Config instances: {!r}, {!r}".format(key, value) + f"char must be Config instances: {key!r}, {value!r}" ) dict.__setitem__(self, key, value) @@ -1036,8 +1036,8 @@ def _add_arguments(self, aliases, flags, classes): # flag sets 'action', so can't have flag & alias with custom action # on the same name raise ArgumentError( - "The alias `{}` for the 'append' sequence " - "config-trait `{}` cannot be also a flag!'".format(key, traitname) + f"The alias `{key}` for the 'append' sequence " + f"config-trait `{traitname}` cannot be also a flag!'" ) # For argcomplete, check if any either an argcompleter metadata tag or method # is available. If so, it should be a callable which takes the command-line key diff --git a/traitlets/traitlets.py b/traitlets/traitlets.py index 97ee9bca..e5376738 100644 --- a/traitlets/traitlets.py +++ b/traitlets/traitlets.py @@ -322,8 +322,7 @@ def _update_target(self, change): setattr(self.target[0], self.target[1], self._transform(change.new)) if getattr(self.source[0], self.source[1]) != change.new: raise TraitError( - "Broken link {}: the source value changed while updating " - "the target.".format(self) + f"Broken link {self}: the source value changed while updating " "the target." ) def _update_source(self, change): @@ -333,8 +332,7 @@ def _update_source(self, change): setattr(self.source[0], self.source[1], self._transform_inv(change.new)) if getattr(self.target[0], self.target[1]) != change.new: raise TraitError( - "Broken link {}: the target value changed while updating " - "the source.".format(self) + f"Broken link {self}: the target value changed while updating " "the source." ) def unlink(self): @@ -532,9 +530,9 @@ def __init__( key = ("metadata-tag", pkg, *sorted(kwargs)) if should_warn(key): warn( - "metadata {} was set from the constructor. " + f"metadata {kwargs} was set from the constructor. " "With traitlets 4.1, metadata should be set using the .tag() method, " - "e.g., Int().tag(key1='value1', key2='value2')".format(kwargs), + "e.g., Int().tag(key1='value1', key2='value2')", DeprecationWarning, stacklevel=stacklevel, ) @@ -2006,8 +2004,8 @@ def validate(self, obj, value): value = self._resolve_string(value) except ImportError as e: raise TraitError( - "The '{}' trait of {} instance must be a type, but " - "{!r} could not be imported".format(self.name, obj, value) + f"The '{self.name}' trait of {obj} instance must be a type, but " + f"{value!r} could not be imported" ) from e try: if issubclass(value, self.klass): # type:ignore[arg-type] @@ -2308,19 +2306,15 @@ def _validate_bounds(trait, obj, value): """ if trait.min is not None and value < trait.min: raise TraitError( - "The value of the '{name}' trait of {klass} instance should " - "not be less than {min_bound}, but a value of {value} was " - "specified".format( - name=trait.name, klass=class_of(obj), value=value, min_bound=trait.min - ) + f"The value of the '{trait.name}' trait of {class_of(obj)} instance should " + f"not be less than {trait.min}, but a value of {value} was " + "specified" ) if trait.max is not None and value > trait.max: raise TraitError( - "The value of the '{name}' trait of {klass} instance should " - "not be greater than {max_bound}, but a value of {value} was " - "specified".format( - name=trait.name, klass=class_of(obj), value=value, max_bound=trait.max - ) + f"The value of the '{trait.name}' trait of {class_of(obj)} instance should " + f"not be greater than {trait.max}, but a value of {value} was " + "specified" ) return value @@ -2460,7 +2454,7 @@ def from_string(self, s): s = s[2:-1] warn( "Supporting extra quotes around Bytes is deprecated in traitlets 5.0. " - "Use {!r} instead of {!r}.".format(s, old_s), + f"Use {s!r} instead of {old_s!r}.", DeprecationWarning, stacklevel=2, ) @@ -2510,9 +2504,7 @@ def from_string(self, s): s = s[1:-1] warn( "Supporting extra quotes around strings is deprecated in traitlets 5.0. " - "You can use {!r} instead of {!r} if you require traitlets >=5.".format( - s, old_s - ), + f"You can use {s!r} instead of {old_s!r} if you require traitlets >=5.", DeprecationWarning, stacklevel=2, ) @@ -3398,11 +3390,8 @@ def from_string_list(self, s_list): return None if len(s_list) == 1 and s_list[0].startswith("{") and s_list[0].endswith("}"): warn( - "--{0}={1} for dict-traits is deprecated in traitlets 5.0. " - "You can pass --{0} ... multiple times to add items to a dict.".format( - self.name, - s_list[0], - ), + f"--{self.name}={s_list[0]} for dict-traits is deprecated in traitlets 5.0. " + f"You can pass --{self.name} ... multiple times to add items to a dict.", DeprecationWarning, stacklevel=2, )