diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3212752e5dc..678a14128a6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.15 + rev: v0.2.0 hooks: - id: ruff args: [--fix, --unsafe-fixes] diff --git a/dev_scripts/update_pt_data.py b/dev_scripts/update_pt_data.py old mode 100755 new mode 100644 index e3f330afb31..ab80ed190d2 --- a/dev_scripts/update_pt_data.py +++ b/dev_scripts/update_pt_data.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - """ Developer script to convert yaml periodic table to json format. Created on Nov 15, 2011. @@ -217,7 +215,7 @@ def gen_iupac_ordering(): ([17], range(6, 1, -1)), ] # At -> F - order = sum((list(product(x, y)) for x, y in order), []) + order = sum((list(product(x, y)) for x, y in order), []) # noqa: RUF017 iupac_ordering_dict = dict(zip([Element.from_row_and_group(row, group) for group, row in order], range(len(order)))) # first clean periodic table of any IUPAC ordering diff --git a/pymatgen/alchemy/materials.py b/pymatgen/alchemy/materials.py index 2447a2b3850..75eb0cd2402 100644 --- a/pymatgen/alchemy/materials.py +++ b/pymatgen/alchemy/materials.py @@ -82,13 +82,12 @@ def redo_next_change(self) -> None: """ if len(self._undone) == 0: raise IndexError("No more changes to redo") - h, s = self._undone.pop() - self.history.append(h) - self.final_structure = s + hist, struct = self._undone.pop() + self.history.append(hist) + self.final_structure = struct def __getattr__(self, name) -> Any: - struct = object.__getattribute__(self, "final_structure") - return getattr(struct, name) + return getattr(self.final_structure, name) def __len__(self) -> int: return len(self.history) diff --git a/pymatgen/analysis/adsorption.py b/pymatgen/analysis/adsorption.py index 58c8fc5386d..44d0c9330cb 100644 --- a/pymatgen/analysis/adsorption.py +++ b/pymatgen/analysis/adsorption.py @@ -298,7 +298,7 @@ def find_adsorption_sites( sites = [site + distance * np.asarray(self.mvec) for site in sites] ads_sites[key] = sites - ads_sites["all"] = sum(ads_sites.values(), []) + ads_sites["all"] = sum(ads_sites.values(), []) # noqa: RUF017 return ads_sites def symm_reduce(self, coords_set, threshold=1e-6): diff --git a/pymatgen/analysis/chemenv/coordination_environments/coordination_geometries.py b/pymatgen/analysis/chemenv/coordination_environments/coordination_geometries.py index 5b293bead09..9156290bf71 100644 --- a/pymatgen/analysis/chemenv/coordination_environments/coordination_geometries.py +++ b/pymatgen/analysis/chemenv/coordination_environments/coordination_geometries.py @@ -397,7 +397,7 @@ def hints(self, hints_info): """ if hints_info["csm"] > self.options["csm_max"]: return [] - return object.__getattribute__(self, f"{self.hints_type}_hints")(hints_info) + return getattr(self, f"{self.hints_type}_hints")(hints_info) def single_cap_hints(self, hints_info): """Return hints for an additional neighbors set, i.e. the voronoi indices that diff --git a/pymatgen/analysis/chemenv/utils/func_utils.py b/pymatgen/analysis/chemenv/utils/func_utils.py index 30837721ad5..92db68fa7e7 100644 --- a/pymatgen/analysis/chemenv/utils/func_utils.py +++ b/pymatgen/analysis/chemenv/utils/func_utils.py @@ -36,7 +36,7 @@ def __init__(self, function, options_dict=None): """ if function not in self.ALLOWED_FUNCTIONS: raise ValueError(f"{function=!r} is not allowed in RatioFunction of type {type(self).__name__}") - self.eval = object.__getattribute__(self, function) + self.eval = getattr(self, function) self.function = function self.setup_parameters(options_dict=options_dict) diff --git a/pymatgen/core/periodic_table.py b/pymatgen/core/periodic_table.py index b53ab3d59f4..68a2a76d17c 100644 --- a/pymatgen/core/periodic_table.py +++ b/pymatgen/core/periodic_table.py @@ -462,7 +462,7 @@ def ground_state_term_symbol(self): "L": L_symbols.index(term[1]), "J": float(term[2:]), } - for term in sum(term_symbols, []) + for term in sum(term_symbols, []) # noqa: RUF017 } multi = [int(item["multiplicity"]) for terms, item in term_symbol_flat.items()] diff --git a/pymatgen/core/sites.py b/pymatgen/core/sites.py index b95ae2de3d7..eb02006d246 100644 --- a/pymatgen/core/sites.py +++ b/pymatgen/core/sites.py @@ -73,7 +73,7 @@ def __init__( def __getattr__(self, attr): # overriding getattr doesn't play nicely with pickle, so we can't use self._properties - props = object.__getattribute__(self, "properties") + props = self.__getattribute__("properties") if attr in props: return props[attr] raise AttributeError(f"{attr=} not found on {type(self).__name__}") diff --git a/pymatgen/io/abinit/inputs.py b/pymatgen/io/abinit/inputs.py index 18d6a9780cd..e01e0087da2 100644 --- a/pymatgen/io/abinit/inputs.py +++ b/pymatgen/io/abinit/inputs.py @@ -1144,8 +1144,7 @@ def __iter__(self): return iter(self._inputs) def __getattr__(self, name): - _inputs = object.__getattribute__(self, "_inputs") - m = getattr(_inputs[0], name) + m = getattr(self._inputs[0], name) if m is None: raise AttributeError( f"Cannot find attribute {type(self).__name__}. Tried in {name} and then in BasicAbinitInput object" diff --git a/pymatgen/io/abinit/pseudos.py b/pymatgen/io/abinit/pseudos.py index 78663f6690c..290d880555e 100644 --- a/pymatgen/io/abinit/pseudos.py +++ b/pymatgen/io/abinit/pseudos.py @@ -645,12 +645,10 @@ class AbinitHeader(dict): def __getattr__(self, name): try: - # Default behavior - return super().__getattribute__(name) + return super().__getattribute__(name) # this is just default behavior except AttributeError: try: - # Try in the dictionary. - return self[name] + return self[name] # if above failed, try the dictionary except KeyError as exc: raise AttributeError(str(exc)) diff --git a/pyproject.toml b/pyproject.toml index 4c932284a4c..e1fa134df2e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ repair-wheel-command = "delocate-wheel --require-archs {delocate_archs} -w {dest [tool.ruff] target-version = "py39" line-length = 120 -select = [ +lint.select = [ "B", # flake8-bugbear "C4", # flake8-comprehensions "D", # pydocstyle @@ -54,8 +54,7 @@ select = [ "W", # pycodestyle warning "YTT", # flake8-2020 ] -ignore = [ - "ANN101", # Missing type annotation for self in method +lint.ignore = [ "B023", # Function definition does not bind loop variable "B028", # No explicit stacklevel keyword argument found "B904", # Within an except clause, raise exceptions with ... @@ -78,11 +77,11 @@ ignore = [ "RUF012", # Disable checks for mutable class args. This is a non-problem. "SIM105", # Use contextlib.suppress(OSError) instead of try-except-pass ] -pydocstyle.convention = "google" -isort.required-imports = ["from __future__ import annotations"] -isort.split-on-trailing-comma = false +lint.pydocstyle.convention = "google" +lint.isort.required-imports = ["from __future__ import annotations"] +lint.isort.split-on-trailing-comma = false -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "__init__.py" = ["F401"] "tests/**" = ["ANN201", "D", "S101"] "tasks.py" = ["D"]