diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c20cf9b..10a0e97e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.23.2 + rev: 0.23.3 hooks: - id: check-github-workflows @@ -29,12 +29,12 @@ repos: - id: mdformat - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.7.0 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.276 + rev: v0.0.281 hooks: - id: ruff args: ["--fix"] diff --git a/pyproject.toml b/pyproject.toml index 5d53379f..13c0b7db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,7 @@ dependencies = ["mypy>=0.990"] test = "mypy --install-types --non-interactive {args:.}" [tool.hatch.envs.lint] -dependencies = ["black==23.3.0", "mdformat>0.7", "ruff==0.0.276"] +dependencies = ["black==23.3.0", "mdformat>0.7", "ruff==0.0.281"] detached = true [tool.hatch.envs.lint.scripts] style = [ diff --git a/traitlets/config/configurable.py b/traitlets/config/configurable.py index 570967aa..41f1f8cf 100644 --- a/traitlets/config/configurable.py +++ b/traitlets/config/configurable.py @@ -189,9 +189,7 @@ def warn(msg): return warnings.warn(msg, UserWarning, stacklevel=9) matches = get_close_matches(name, traits) - msg = "Config option `{option}` not recognized by `{klass}`.".format( - option=name, klass=self.__class__.__name__ - ) + msg = f"Config option `{name}` not recognized by `{self.__class__.__name__}`." if len(matches) == 1: msg += f" Did you mean `{matches[0]}`?" diff --git a/traitlets/config/sphinxdoc.py b/traitlets/config/sphinxdoc.py index 92c2d64d..a69d89f9 100644 --- a/traitlets/config/sphinxdoc.py +++ b/traitlets/config/sphinxdoc.py @@ -124,10 +124,10 @@ def reverse_aliases(app): # Treat flags which set one trait to True as aliases. for flag, (cfg, _) in app.flags.items(): if len(cfg) == 1: - classname = list(cfg)[0] + classname = next(iter(cfg)) cls_cfg = cfg[classname] if len(cls_cfg) == 1: - traitname = list(cls_cfg)[0] + traitname = next(iter(cls_cfg)) if cls_cfg[traitname] is True: res[classname + "." + traitname].append(flag) diff --git a/traitlets/traitlets.py b/traitlets/traitlets.py index 06b4d82d..97ee9bca 100644 --- a/traitlets/traitlets.py +++ b/traitlets/traitlets.py @@ -2903,7 +2903,8 @@ def from_string_list(self, s_list): item_from_string = self.item_from_string else: # backward-compat: allow item_from_string to ignore index arg - item_from_string = lambda s, index=None: self.item_from_string(s) # noqa[E371] + def item_from_string(s, index=None): + return self.item_from_string(s) # noqa[E371] return self.klass( [item_from_string(s, index=idx) for idx, s in enumerate(s_list)] @@ -3426,10 +3427,7 @@ def item_from_string(self, s): if "=" not in s: raise TraitError( - "'{}' options must have the form 'key=value', got {}".format( - self.__class__.__name__, - repr(s), - ) + f"'{self.__class__.__name__}' options must have the form 'key=value', got {s!r}" ) key, value = s.split("=", 1) @@ -3521,7 +3519,7 @@ def __init__(self, enum_class, default_value=None, **kwargs): assert issubclass(enum_class, enum.Enum), "REQUIRE: enum.Enum, but was: %r" % enum_class allow_none = kwargs.get("allow_none", False) if default_value is None and not allow_none: - default_value = list(enum_class.__members__.values())[0] + default_value = next(iter(enum_class.__members__.values())) super().__init__(default_value=default_value, **kwargs) self.enum_class = enum_class self.name_prefix = enum_class.__name__ + "." diff --git a/traitlets/utils/warnings.py b/traitlets/utils/warnings.py index d2b04fd7..216b23dc 100644 --- a/traitlets/utils/warnings.py +++ b/traitlets/utils/warnings.py @@ -17,9 +17,7 @@ def deprecated_method(method, cls, method_name, msg): Uses warn_explicit to bind warning to method definition instead of triggering code, which isn't relevant. """ - warn_msg = "{classname}.{method_name} is deprecated in traitlets 4.1: {msg}".format( - classname=cls.__name__, method_name=method_name, msg=msg - ) + warn_msg = f"{cls.__name__}.{method_name} is deprecated in traitlets 4.1: {msg}" for parent in inspect.getmro(cls): if method_name in parent.__dict__: