Skip to content

Commit 561ff1b

Browse files
authored
style: enable N804 and N805 (#4024)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Updated the linting tool to the latest version, enhancing code quality checks. - Introduced stricter naming conventions for method arguments in the linting rules. - **Bug Fixes** - Improved the functionality of instance and class methods, ensuring proper context usage. - **Documentation** - Updated the method signatures in tests to reflect best practices for class-level attributes. - **Refactor** - Standardized method signatures across multiple test classes to follow Python conventions. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
1 parent a7d4294 commit 561ff1b

14 files changed

Lines changed: 208 additions & 206 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repos:
2929
exclude: ^source/3rdparty
3030
- repo: https://github.com/astral-sh/ruff-pre-commit
3131
# Ruff version.
32-
rev: v0.5.4
32+
rev: v0.5.5
3333
hooks:
3434
- id: ruff
3535
args: ["--fix"]

deepmd/pt/model/task/ener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def output_def(self):
181181
def serialize(self) -> dict:
182182
raise NotImplementedError
183183

184-
def deserialize(cls) -> "EnergyFittingNetDirect":
184+
def deserialize(self) -> "EnergyFittingNetDirect":
185185
raise NotImplementedError
186186

187187
def change_type_map(

deepmd/utils/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def get_plugin(self, key) -> object:
7575

7676

7777
class VariantMeta:
78-
def __call__(cls, *args, **kwargs):
78+
def __call__(self, *args, **kwargs):
7979
"""Remove `type` and keys that starts with underline."""
80-
obj = cls.__new__(cls, *args, **kwargs)
80+
obj = self.__new__(self, *args, **kwargs)
8181
kwargs.pop("type", None)
8282
to_pop = []
8383
for kk in kwargs:

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ select = [
348348
"TID253", # banned-module-level-imports
349349
"T20", # ban print
350350
"B904", # raise-without-from-inside-except
351+
"N804", # invalid-first-argument-name-for-class-method
352+
"N805", # invalid-first-argument-name-for-method
351353
]
352354

353355
ignore = [

source/tests/tf/test_adjust_sel.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ def _init_models():
7272

7373
class TestDeepPotAAdjustSel(unittest.TestCase):
7474
@classmethod
75-
def setUpClass(self):
75+
def setUpClass(cls):
7676
INPUT, FROZEN_MODEL, DECREASED_MODEL, INCREASED_MODEL = _init_models()
77-
self.dp_original = DeepPot(FROZEN_MODEL)
78-
self.dp_decreased = DeepPot(DECREASED_MODEL)
79-
self.dp_increased = DeepPot(INCREASED_MODEL)
80-
self.coords = np.array(
77+
cls.dp_original = DeepPot(FROZEN_MODEL)
78+
cls.dp_decreased = DeepPot(DECREASED_MODEL)
79+
cls.dp_increased = DeepPot(INCREASED_MODEL)
80+
cls.coords = np.array(
8181
[
8282
12.83,
8383
2.56,
@@ -99,8 +99,8 @@ def setUpClass(self):
9999
1.56,
100100
]
101101
)
102-
self.atype = [0, 1, 1, 0, 1, 1]
103-
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
102+
cls.atype = [0, 1, 1, 0, 1, 1]
103+
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
104104

105105
def test_attrs(self):
106106
self.assertEqual(self.dp_original.get_ntypes(), 2)

source/tests/tf/test_finetune_se_atten.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ def compressible_model(jdata):
199199
cls.VALID_DATAS = VALID_DATAS
200200

201201
@classmethod
202-
def tearDownClass(self):
203-
for i in range(len(self.INPUT_PRES)):
204-
_file_delete(self.INPUT_PRES[i])
205-
_file_delete(self.INPUT_FINETUNES[i])
206-
_file_delete(self.INPUT_FINETUNE_MIXS[i])
207-
_file_delete(self.PRE_MODELS[i])
208-
_file_delete(self.FINETUNED_MODELS[i])
209-
_file_delete(self.FINETUNED_MODEL_MIXS[i])
202+
def tearDownClass(cls):
203+
for i in range(len(cls.INPUT_PRES)):
204+
_file_delete(cls.INPUT_PRES[i])
205+
_file_delete(cls.INPUT_FINETUNES[i])
206+
_file_delete(cls.INPUT_FINETUNE_MIXS[i])
207+
_file_delete(cls.PRE_MODELS[i])
208+
_file_delete(cls.FINETUNED_MODELS[i])
209+
_file_delete(cls.FINETUNED_MODEL_MIXS[i])
210210
_file_delete("out.json")
211211
_file_delete("model.ckpt.meta")
212212
_file_delete("model.ckpt.index")

source/tests/tf/test_model_compression_se_a.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ def setUpModule():
8787

8888
class TestDeepPotAPBC(unittest.TestCase):
8989
@classmethod
90-
def setUpClass(self):
91-
self.dp_original = DeepPot(FROZEN_MODEL)
92-
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
93-
self.coords = np.array(
90+
def setUpClass(cls):
91+
cls.dp_original = DeepPot(FROZEN_MODEL)
92+
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
93+
cls.coords = np.array(
9494
[
9595
12.83,
9696
2.56,
@@ -112,8 +112,8 @@ def setUpClass(self):
112112
1.56,
113113
]
114114
)
115-
self.atype = [0, 1, 1, 0, 1, 1]
116-
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
115+
cls.atype = [0, 1, 1, 0, 1, 1]
116+
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
117117

118118
def test_attrs(self):
119119
self.assertEqual(self.dp_original.get_ntypes(), 2)
@@ -211,10 +211,10 @@ def test_2frame_atm(self):
211211

212212
class TestDeepPotANoPBC(unittest.TestCase):
213213
@classmethod
214-
def setUpClass(self):
215-
self.dp_original = DeepPot(FROZEN_MODEL)
216-
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
217-
self.coords = np.array(
214+
def setUpClass(cls):
215+
cls.dp_original = DeepPot(FROZEN_MODEL)
216+
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
217+
cls.coords = np.array(
218218
[
219219
12.83,
220220
2.56,
@@ -236,8 +236,8 @@ def setUpClass(self):
236236
1.56,
237237
]
238238
)
239-
self.atype = [0, 1, 1, 0, 1, 1]
240-
self.box = None
239+
cls.atype = [0, 1, 1, 0, 1, 1]
240+
cls.box = None
241241

242242
def test_1frame(self):
243243
ee0, ff0, vv0 = self.dp_original.eval(
@@ -319,10 +319,10 @@ def test_2frame_atm(self):
319319

320320
class TestDeepPotALargeBoxNoPBC(unittest.TestCase):
321321
@classmethod
322-
def setUpClass(self):
323-
self.dp_original = DeepPot(FROZEN_MODEL)
324-
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
325-
self.coords = np.array(
322+
def setUpClass(cls):
323+
cls.dp_original = DeepPot(FROZEN_MODEL)
324+
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
325+
cls.coords = np.array(
326326
[
327327
12.83,
328328
2.56,
@@ -344,8 +344,8 @@ def setUpClass(self):
344344
1.56,
345345
]
346346
)
347-
self.atype = [0, 1, 1, 0, 1, 1]
348-
self.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
347+
cls.atype = [0, 1, 1, 0, 1, 1]
348+
cls.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
349349

350350
def test_1frame(self):
351351
ee0, ff0, vv0 = self.dp_original.eval(
@@ -427,10 +427,10 @@ def test_ase(self):
427427

428428
class TestDeepPotAPBCExcludeTypes(unittest.TestCase):
429429
@classmethod
430-
def setUpClass(self):
431-
self.dp_original = DeepPot(FROZEN_MODEL_ET)
432-
self.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
433-
self.coords = np.array(
430+
def setUpClass(cls):
431+
cls.dp_original = DeepPot(FROZEN_MODEL_ET)
432+
cls.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
433+
cls.coords = np.array(
434434
[
435435
12.83,
436436
2.56,
@@ -452,11 +452,11 @@ def setUpClass(self):
452452
1.56,
453453
]
454454
)
455-
self.atype = [0, 1, 1, 0, 1, 1]
456-
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
455+
cls.atype = [0, 1, 1, 0, 1, 1]
456+
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
457457

458458
@classmethod
459-
def tearDownClass(self):
459+
def tearDownClass(cls):
460460
_file_delete(INPUT_ET)
461461
_file_delete(FROZEN_MODEL_ET)
462462
_file_delete(COMPRESSED_MODEL_ET)

source/tests/tf/test_model_compression_se_a_ebd.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ def setUpModule():
9999

100100
class TestDeepPotAPBC(unittest.TestCase):
101101
@classmethod
102-
def setUpClass(self):
103-
self.dp_original = DeepPot(FROZEN_MODEL)
104-
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
105-
self.coords = np.array(
102+
def setUpClass(cls):
103+
cls.dp_original = DeepPot(FROZEN_MODEL)
104+
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
105+
cls.coords = np.array(
106106
[
107107
12.83,
108108
2.56,
@@ -124,8 +124,8 @@ def setUpClass(self):
124124
1.56,
125125
]
126126
)
127-
self.atype = [0, 1, 1, 0, 1, 1]
128-
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
127+
cls.atype = [0, 1, 1, 0, 1, 1]
128+
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
129129

130130
def test_attrs(self):
131131
self.assertEqual(self.dp_original.get_ntypes(), 2)
@@ -223,10 +223,10 @@ def test_2frame_atm(self):
223223

224224
class TestDeepPotANoPBC(unittest.TestCase):
225225
@classmethod
226-
def setUpClass(self):
227-
self.dp_original = DeepPot(FROZEN_MODEL)
228-
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
229-
self.coords = np.array(
226+
def setUpClass(cls):
227+
cls.dp_original = DeepPot(FROZEN_MODEL)
228+
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
229+
cls.coords = np.array(
230230
[
231231
12.83,
232232
2.56,
@@ -248,8 +248,8 @@ def setUpClass(self):
248248
1.56,
249249
]
250250
)
251-
self.atype = [0, 1, 1, 0, 1, 1]
252-
self.box = None
251+
cls.atype = [0, 1, 1, 0, 1, 1]
252+
cls.box = None
253253

254254
def test_1frame(self):
255255
ee0, ff0, vv0 = self.dp_original.eval(
@@ -331,10 +331,10 @@ def test_2frame_atm(self):
331331

332332
class TestDeepPotALargeBoxNoPBC(unittest.TestCase):
333333
@classmethod
334-
def setUpClass(self):
335-
self.dp_original = DeepPot(FROZEN_MODEL)
336-
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
337-
self.coords = np.array(
334+
def setUpClass(cls):
335+
cls.dp_original = DeepPot(FROZEN_MODEL)
336+
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
337+
cls.coords = np.array(
338338
[
339339
12.83,
340340
2.56,
@@ -356,8 +356,8 @@ def setUpClass(self):
356356
1.56,
357357
]
358358
)
359-
self.atype = [0, 1, 1, 0, 1, 1]
360-
self.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
359+
cls.atype = [0, 1, 1, 0, 1, 1]
360+
cls.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
361361

362362
def test_1frame(self):
363363
ee0, ff0, vv0 = self.dp_original.eval(
@@ -439,10 +439,10 @@ def test_ase(self):
439439

440440
class TestDeepPotAPBCExcludeTypes(unittest.TestCase):
441441
@classmethod
442-
def setUpClass(self):
443-
self.dp_original = DeepPot(FROZEN_MODEL_ET)
444-
self.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
445-
self.coords = np.array(
442+
def setUpClass(cls):
443+
cls.dp_original = DeepPot(FROZEN_MODEL_ET)
444+
cls.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
445+
cls.coords = np.array(
446446
[
447447
12.83,
448448
2.56,
@@ -464,11 +464,11 @@ def setUpClass(self):
464464
1.56,
465465
]
466466
)
467-
self.atype = [0, 1, 1, 0, 1, 1]
468-
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
467+
cls.atype = [0, 1, 1, 0, 1, 1]
468+
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
469469

470470
@classmethod
471-
def tearDownClass(self):
471+
def tearDownClass(cls):
472472
_file_delete(INPUT_ET)
473473
_file_delete(FROZEN_MODEL_ET)
474474
_file_delete(COMPRESSED_MODEL_ET)

0 commit comments

Comments
 (0)