Skip to content

Commit c57d19f

Browse files
Copilotnjzjz
andauthored
feat: add comprehensive type hints to core modules excluding backends and tests (#4936)
- [x] Add comprehensive type hints to core modules excluding backends and tests - [x] **Fixed type annotation issues from code review:** - Fixed `head` parameter type from `Any` to `str` in calculator.py - Fixed `neighbor_list` parameter type to use proper ASE NeighborList type annotation - Fixed `**kwargs` type from `object` to `Any` in deep_polar.py - Fixed `write_model_devi_out` return type from `None` to `np.ndarray` to match actual return value - Fixed `get_natoms_vec` return type from `list[int]` to `np.ndarray` to match actual return type - Fixed `_get_natoms_2` return type from `list[int]` to `tuple[int, np.ndarray]` to match actual return values - Fixed `make_index` return type from `dict[str, int]` to `str` to match actual return value - Added missing imports for type annotations (ASE NeighborList, Any) **Current status:** All type annotation suggestions from code review have been addressed. All ruff checks pass with zero violations. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/deepmodeling/deepmd-kit/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: njzjz <[email protected]>
1 parent aa44098 commit c57d19f

37 files changed

+432
-244
lines changed

deepmd/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
modules for performance.
99
"""
1010

11+
from typing import (
12+
TYPE_CHECKING,
13+
Any,
14+
)
15+
16+
if TYPE_CHECKING:
17+
from deepmd.infer import DeepPotential as DeepPotentialType
18+
1119
try:
1220
from deepmd._version import version as __version__
1321
except ImportError:
@@ -16,7 +24,7 @@
1624
)
1725

1826

19-
def DeepPotential(*args, **kwargs):
27+
def DeepPotential(*args: Any, **kwargs: Any) -> "DeepPotentialType":
2028
"""Factory function that forwards to DeepEval (for compatibility
2129
and performance).
2230

deepmd/calculator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
)
77
from typing import (
88
TYPE_CHECKING,
9+
Any,
910
ClassVar,
1011
Optional,
1112
Union,
@@ -25,6 +26,9 @@
2526
from ase import (
2627
Atoms,
2728
)
29+
from ase.neighborlist import (
30+
NeighborList,
31+
)
2832

2933
__all__ = ["DP"]
3034

@@ -85,9 +89,9 @@ def __init__(
8589
model: Union[str, "Path"],
8690
label: str = "DP",
8791
type_dict: Optional[dict[str, int]] = None,
88-
neighbor_list=None,
89-
head=None,
90-
**kwargs,
92+
neighbor_list: Optional["NeighborList"] = None,
93+
head: Optional[str] = None,
94+
**kwargs: Any,
9195
) -> None:
9296
Calculator.__init__(self, label=label, **kwargs)
9397
self.dp = DeepPot(

deepmd/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def symlink_prefix_files(old_prefix: str, new_prefix: str) -> None:
284284
shutil.copyfile(ori_ff, new_ff)
285285

286286

287-
def get_hash(obj) -> str:
287+
def get_hash(obj: Any) -> str:
288288
"""Get hash of object.
289289
290290
Parameters

deepmd/entrypoints/convert_backend.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
2+
from typing import (
3+
Any,
4+
)
5+
26
from deepmd.backend.backend import (
37
Backend,
48
)
@@ -8,7 +12,7 @@ def convert_backend(
812
*, # Enforce keyword-only arguments
913
INPUT: str,
1014
OUTPUT: str,
11-
**kwargs,
15+
**kwargs: Any,
1216
) -> None:
1317
"""Convert a model file from one backend to another.
1418

deepmd/entrypoints/doc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""Module that prints train input arguments docstrings."""
33

4+
from typing import (
5+
Any,
6+
)
7+
48
from deepmd.utils.argcheck import (
59
gen_doc,
610
gen_json,
@@ -11,7 +15,7 @@
1115

1216

1317
def doc_train_input(
14-
*, out_type: str = "rst", multi_task: bool = False, **kwargs
18+
*, out_type: str = "rst", multi_task: bool = False, **kwargs: Any
1519
) -> None:
1620
"""Print out trining input arguments to console."""
1721
if out_type == "rst":

deepmd/entrypoints/eval_desc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Path,
88
)
99
from typing import (
10+
Any,
1011
Optional,
1112
)
1213

@@ -34,7 +35,7 @@ def eval_desc(
3435
datafile: str,
3536
output: str = "desc",
3637
head: Optional[str] = None,
37-
**kwargs,
38+
**kwargs: Any,
3839
) -> None:
3940
"""Evaluate descriptors for given systems.
4041

deepmd/entrypoints/gui.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""DP-GUI entrypoint."""
33

4+
from typing import (
5+
Any,
6+
)
47

5-
def start_dpgui(*, port: int, bind_all: bool, **kwargs) -> None:
8+
9+
def start_dpgui(*, port: int, bind_all: bool, **kwargs: Any) -> None:
610
"""Host DP-GUI server.
711
812
Parameters

deepmd/entrypoints/ipi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ROOT_DIR = get_op_dir()
1616

1717

18-
def _program(name: str, args: list[str]):
18+
def _program(name: str, args: list[str]) -> None:
1919
"""Execute a program.
2020
2121
Parameters

deepmd/entrypoints/neighbor_stat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import logging
33
from typing import (
4+
Any,
45
Optional,
56
)
67

@@ -24,8 +25,8 @@ def neighbor_stat(
2425
type_map: Optional[list[str]],
2526
mixed_type: bool = False,
2627
backend: str = "tensorflow",
27-
**kwargs,
28-
):
28+
**kwargs: Any,
29+
) -> None:
2930
"""Calculate neighbor statistics.
3031
3132
Parameters

deepmd/entrypoints/show.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import logging
3+
from typing import (
4+
Any,
5+
)
36

47
from deepmd.infer.deep_eval import (
58
DeepEval,
@@ -19,7 +22,7 @@ def show(
1922
*,
2023
INPUT: str,
2124
ATTRIBUTES: list[str],
22-
**kwargs,
25+
**kwargs: Any,
2326
) -> None:
2427
model = DeepEval(INPUT, head=0)
2528
model_params = model.get_model_def_script()

0 commit comments

Comments
 (0)