Skip to content

Commit d725325

Browse files
committed
bump ruff to 0.2.0, fix pyproject config, fix PLC2801 (object.__getattribute__ -> getattr), add line ignores for RUF017
1 parent 367d581 commit d725325

File tree

11 files changed

+20
-27
lines changed

11 files changed

+20
-27
lines changed

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ci:
88

99
repos:
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.1.15
11+
rev: v0.2.0
1212
hooks:
1313
- id: ruff
1414
args: [--fix, --unsafe-fixes]

Diff for: dev_scripts/update_pt_data.py

100755100644
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
"""
42
Developer script to convert yaml periodic table to json format.
53
Created on Nov 15, 2011.
@@ -217,7 +215,7 @@ def gen_iupac_ordering():
217215
([17], range(6, 1, -1)),
218216
] # At -> F
219217

220-
order = sum((list(product(x, y)) for x, y in order), [])
218+
order = sum((list(product(x, y)) for x, y in order), []) # noqa: RUF017
221219
iupac_ordering_dict = dict(zip([Element.from_row_and_group(row, group) for group, row in order], range(len(order))))
222220

223221
# first clean periodic table of any IUPAC ordering

Diff for: pymatgen/alchemy/materials.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ def redo_next_change(self) -> None:
8282
"""
8383
if len(self._undone) == 0:
8484
raise IndexError("No more changes to redo")
85-
h, s = self._undone.pop()
86-
self.history.append(h)
87-
self.final_structure = s
85+
hist, struct = self._undone.pop()
86+
self.history.append(hist)
87+
self.final_structure = struct
8888

8989
def __getattr__(self, name) -> Any:
90-
struct = object.__getattribute__(self, "final_structure")
91-
return getattr(struct, name)
90+
return getattr(self.final_structure, name)
9291

9392
def __len__(self) -> int:
9493
return len(self.history)

Diff for: pymatgen/analysis/adsorption.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def find_adsorption_sites(
298298
sites = [site + distance * np.asarray(self.mvec) for site in sites]
299299

300300
ads_sites[key] = sites
301-
ads_sites["all"] = sum(ads_sites.values(), [])
301+
ads_sites["all"] = sum(ads_sites.values(), []) # noqa: RUF017
302302
return ads_sites
303303

304304
def symm_reduce(self, coords_set, threshold=1e-6):

Diff for: pymatgen/analysis/chemenv/coordination_environments/coordination_geometries.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def hints(self, hints_info):
397397
"""
398398
if hints_info["csm"] > self.options["csm_max"]:
399399
return []
400-
return object.__getattribute__(self, f"{self.hints_type}_hints")(hints_info)
400+
return getattr(self, f"{self.hints_type}_hints")(hints_info)
401401

402402
def single_cap_hints(self, hints_info):
403403
"""Return hints for an additional neighbors set, i.e. the voronoi indices that

Diff for: pymatgen/analysis/chemenv/utils/func_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, function, options_dict=None):
3636
"""
3737
if function not in self.ALLOWED_FUNCTIONS:
3838
raise ValueError(f"{function=!r} is not allowed in RatioFunction of type {type(self).__name__}")
39-
self.eval = object.__getattribute__(self, function)
39+
self.eval = getattr(self, function)
4040
self.function = function
4141
self.setup_parameters(options_dict=options_dict)
4242

Diff for: pymatgen/core/periodic_table.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def ground_state_term_symbol(self):
462462
"L": L_symbols.index(term[1]),
463463
"J": float(term[2:]),
464464
}
465-
for term in sum(term_symbols, [])
465+
for term in sum(term_symbols, []) # noqa: RUF017
466466
}
467467

468468
multi = [int(item["multiplicity"]) for terms, item in term_symbol_flat.items()]

Diff for: pymatgen/core/sites.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373

7474
def __getattr__(self, attr):
7575
# overriding getattr doesn't play nicely with pickle, so we can't use self._properties
76-
props = object.__getattribute__(self, "properties")
76+
props = self.__getattribute__("properties")
7777
if attr in props:
7878
return props[attr]
7979
raise AttributeError(f"{attr=} not found on {type(self).__name__}")

Diff for: pymatgen/io/abinit/inputs.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,7 @@ def __iter__(self):
11441144
return iter(self._inputs)
11451145

11461146
def __getattr__(self, name):
1147-
_inputs = object.__getattribute__(self, "_inputs")
1148-
m = getattr(_inputs[0], name)
1147+
m = getattr(self._inputs[0], name)
11491148
if m is None:
11501149
raise AttributeError(
11511150
f"Cannot find attribute {type(self).__name__}. Tried in {name} and then in BasicAbinitInput object"

Diff for: pymatgen/io/abinit/pseudos.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,10 @@ class AbinitHeader(dict):
645645

646646
def __getattr__(self, name):
647647
try:
648-
# Default behavior
649-
return super().__getattribute__(name)
648+
return super().__getattribute__(name) # this is just default behavior
650649
except AttributeError:
651650
try:
652-
# Try in the dictionary.
653-
return self[name]
651+
return self[name] # if above failed, try the dictionary
654652
except KeyError as exc:
655653
raise AttributeError(str(exc))
656654

Diff for: pyproject.toml

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repair-wheel-command = "delocate-wheel --require-archs {delocate_archs} -w {dest
2222
[tool.ruff]
2323
target-version = "py39"
2424
line-length = 120
25-
select = [
25+
lint.select = [
2626
"B", # flake8-bugbear
2727
"C4", # flake8-comprehensions
2828
"D", # pydocstyle
@@ -54,8 +54,7 @@ select = [
5454
"W", # pycodestyle warning
5555
"YTT", # flake8-2020
5656
]
57-
ignore = [
58-
"ANN101", # Missing type annotation for self in method
57+
lint.ignore = [
5958
"B023", # Function definition does not bind loop variable
6059
"B028", # No explicit stacklevel keyword argument found
6160
"B904", # Within an except clause, raise exceptions with ...
@@ -78,11 +77,11 @@ ignore = [
7877
"RUF012", # Disable checks for mutable class args. This is a non-problem.
7978
"SIM105", # Use contextlib.suppress(OSError) instead of try-except-pass
8079
]
81-
pydocstyle.convention = "google"
82-
isort.required-imports = ["from __future__ import annotations"]
83-
isort.split-on-trailing-comma = false
80+
lint.pydocstyle.convention = "google"
81+
lint.isort.required-imports = ["from __future__ import annotations"]
82+
lint.isort.split-on-trailing-comma = false
8483

85-
[tool.ruff.per-file-ignores]
84+
[tool.ruff.lint.per-file-ignores]
8685
"__init__.py" = ["F401"]
8786
"tests/**" = ["ANN201", "D", "S101"]
8887
"tasks.py" = ["D"]

0 commit comments

Comments
 (0)