Skip to content

Commit

Permalink
bump ruff to 0.2.0, fix pyproject config, fix PLC2801 (object.__getat…
Browse files Browse the repository at this point in the history
…tribute__ -> getattr), add line ignores for RUF017
  • Loading branch information
janosh committed Feb 2, 2024
1 parent 367d581 commit dca98be
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions dev_scripts/update_pt_data.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

"""
Developer script to convert yaml periodic table to json format.
Created on Nov 15, 2011.
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions pymatgen/alchemy/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/adsorption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/chemenv/utils/func_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}")
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/abinit/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ def __iter__(self):
return iter(self._inputs)

def __getattr__(self, name):
_inputs = object.__getattribute__(self, "_inputs")
_inputs = self.__getattribute__("_inputs")
m = getattr(_inputs[0], name)
if m is None:
raise AttributeError(
Expand Down
6 changes: 2 additions & 4 deletions pymatgen/io/abinit/pseudos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ...
Expand All @@ -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"]
Expand Down

0 comments on commit dca98be

Please sign in to comment.