Skip to content

Commit

Permalink
style: enable N804 and N805 (deepmodeling#4024)
Browse files Browse the repository at this point in the history
<!-- 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 <[email protected]>
  • Loading branch information
njzjz authored Jul 26, 2024
1 parent a7d4294 commit 561ff1b
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
exclude: ^source/3rdparty
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.4
rev: v0.5.5
hooks:
- id: ruff
args: ["--fix"]
Expand Down
2 changes: 1 addition & 1 deletion deepmd/pt/model/task/ener.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def output_def(self):
def serialize(self) -> dict:
raise NotImplementedError

def deserialize(cls) -> "EnergyFittingNetDirect":
def deserialize(self) -> "EnergyFittingNetDirect":
raise NotImplementedError

def change_type_map(
Expand Down
4 changes: 2 additions & 2 deletions deepmd/utils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def get_plugin(self, key) -> object:


class VariantMeta:
def __call__(cls, *args, **kwargs):
def __call__(self, *args, **kwargs):
"""Remove `type` and keys that starts with underline."""
obj = cls.__new__(cls, *args, **kwargs)
obj = self.__new__(self, *args, **kwargs)
kwargs.pop("type", None)
to_pop = []
for kk in kwargs:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ select = [
"TID253", # banned-module-level-imports
"T20", # ban print
"B904", # raise-without-from-inside-except
"N804", # invalid-first-argument-name-for-class-method
"N805", # invalid-first-argument-name-for-method
]

ignore = [
Expand Down
14 changes: 7 additions & 7 deletions source/tests/tf/test_adjust_sel.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def _init_models():

class TestDeepPotAAdjustSel(unittest.TestCase):
@classmethod
def setUpClass(self):
def setUpClass(cls):
INPUT, FROZEN_MODEL, DECREASED_MODEL, INCREASED_MODEL = _init_models()
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_decreased = DeepPot(DECREASED_MODEL)
self.dp_increased = DeepPot(INCREASED_MODEL)
self.coords = np.array(
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_decreased = DeepPot(DECREASED_MODEL)
cls.dp_increased = DeepPot(INCREASED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -99,8 +99,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_attrs(self):
self.assertEqual(self.dp_original.get_ntypes(), 2)
Expand Down
16 changes: 8 additions & 8 deletions source/tests/tf/test_finetune_se_atten.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ def compressible_model(jdata):
cls.VALID_DATAS = VALID_DATAS

@classmethod
def tearDownClass(self):
for i in range(len(self.INPUT_PRES)):
_file_delete(self.INPUT_PRES[i])
_file_delete(self.INPUT_FINETUNES[i])
_file_delete(self.INPUT_FINETUNE_MIXS[i])
_file_delete(self.PRE_MODELS[i])
_file_delete(self.FINETUNED_MODELS[i])
_file_delete(self.FINETUNED_MODEL_MIXS[i])
def tearDownClass(cls):
for i in range(len(cls.INPUT_PRES)):
_file_delete(cls.INPUT_PRES[i])
_file_delete(cls.INPUT_FINETUNES[i])
_file_delete(cls.INPUT_FINETUNE_MIXS[i])
_file_delete(cls.PRE_MODELS[i])
_file_delete(cls.FINETUNED_MODELS[i])
_file_delete(cls.FINETUNED_MODEL_MIXS[i])
_file_delete("out.json")
_file_delete("model.ckpt.meta")
_file_delete("model.ckpt.index")
Expand Down
50 changes: 25 additions & 25 deletions source/tests/tf/test_model_compression_se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def setUpModule():

class TestDeepPotAPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -112,8 +112,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_attrs(self):
self.assertEqual(self.dp_original.get_ntypes(), 2)
Expand Down Expand Up @@ -211,10 +211,10 @@ def test_2frame_atm(self):

class TestDeepPotANoPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -236,8 +236,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = None
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = None

def test_1frame(self):
ee0, ff0, vv0 = self.dp_original.eval(
Expand Down Expand Up @@ -319,10 +319,10 @@ def test_2frame_atm(self):

class TestDeepPotALargeBoxNoPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -344,8 +344,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_1frame(self):
ee0, ff0, vv0 = self.dp_original.eval(
Expand Down Expand Up @@ -427,10 +427,10 @@ def test_ase(self):

class TestDeepPotAPBCExcludeTypes(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL_ET)
self.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL_ET)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -452,11 +452,11 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

@classmethod
def tearDownClass(self):
def tearDownClass(cls):
_file_delete(INPUT_ET)
_file_delete(FROZEN_MODEL_ET)
_file_delete(COMPRESSED_MODEL_ET)
Expand Down
50 changes: 25 additions & 25 deletions source/tests/tf/test_model_compression_se_a_ebd.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ def setUpModule():

class TestDeepPotAPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -124,8 +124,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_attrs(self):
self.assertEqual(self.dp_original.get_ntypes(), 2)
Expand Down Expand Up @@ -223,10 +223,10 @@ def test_2frame_atm(self):

class TestDeepPotANoPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -248,8 +248,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = None
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = None

def test_1frame(self):
ee0, ff0, vv0 = self.dp_original.eval(
Expand Down Expand Up @@ -331,10 +331,10 @@ def test_2frame_atm(self):

class TestDeepPotALargeBoxNoPBC(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL)
self.dp_compressed = DeepPot(COMPRESSED_MODEL)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -356,8 +356,8 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([19.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

def test_1frame(self):
ee0, ff0, vv0 = self.dp_original.eval(
Expand Down Expand Up @@ -439,10 +439,10 @@ def test_ase(self):

class TestDeepPotAPBCExcludeTypes(unittest.TestCase):
@classmethod
def setUpClass(self):
self.dp_original = DeepPot(FROZEN_MODEL_ET)
self.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
self.coords = np.array(
def setUpClass(cls):
cls.dp_original = DeepPot(FROZEN_MODEL_ET)
cls.dp_compressed = DeepPot(COMPRESSED_MODEL_ET)
cls.coords = np.array(
[
12.83,
2.56,
Expand All @@ -464,11 +464,11 @@ def setUpClass(self):
1.56,
]
)
self.atype = [0, 1, 1, 0, 1, 1]
self.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])
cls.atype = [0, 1, 1, 0, 1, 1]
cls.box = np.array([13.0, 0.0, 0.0, 0.0, 13.0, 0.0, 0.0, 0.0, 13.0])

@classmethod
def tearDownClass(self):
def tearDownClass(cls):
_file_delete(INPUT_ET)
_file_delete(FROZEN_MODEL_ET)
_file_delete(COMPRESSED_MODEL_ET)
Expand Down
Loading

0 comments on commit 561ff1b

Please sign in to comment.