Skip to content

Commit 626e692

Browse files
authored
chore: improve type annotations (#659)
I give up fix type annotations in all files, but it's meaningful to fix the top-module files `dpdata/*.py`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added `name` property to `DPDataCalculator` class. - Introduced assertion for `rdkit_mol` in bond order system. - **Improvements** - Enhanced type hinting across various functions and methods. - Added decorators and type assertion checks for better code validation. - **Maintenance** - Introduced a GitHub Actions workflow for running Pyright type checker. - Updated dependencies and configurations in `pyproject.toml`. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent a7bf93d commit 626e692

File tree

180 files changed

+653
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+653
-162
lines changed

.github/workflows/pyright.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
on:
2+
- push
3+
- pull_request
4+
5+
name: Type checker
6+
jobs:
7+
pyright:
8+
name: pyright
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@master
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: '3.12'
15+
- run: pip install uv
16+
- run: uv pip install --system -e .[amber,ase,pymatgen] rdkit openbabel-wheel
17+
- uses: jakebailey/pyright-action@v2
18+
with:
19+
version: 1.1.363

benchmark/test_import.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import subprocess
24
import sys
35

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# add these directories to sys.path here. If the directory is relative to the
1212
# documentation root, use os.path.abspath to make it absolute, like shown here.
1313
#
14+
from __future__ import annotations
15+
1416
import os
1517
import subprocess as sp
1618
import sys

docs/make_format.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
from __future__ import annotations
2+
13
import csv
24
import os
5+
import sys
36
from collections import defaultdict
47
from inspect import Parameter, Signature, cleandoc, signature
5-
from typing import Literal
8+
9+
if sys.version_info >= (3, 8):
10+
from typing import Literal
11+
else:
12+
from typing_extensions import Literal
613

714
from numpydoc.docscrape import Parameter as numpydoc_Parameter
815
from numpydoc.docscrape_sphinx import SphinxDocString

docs/nb/try_dpdata.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
16+
"from __future__ import annotations\n",
17+
"\n",
1618
"import dpdata"
1719
]
1820
},

dpdata/__about__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
from __future__ import annotations
2+
13
__version__ = "unknown"

dpdata/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from . import lammps, md, vasp
24
from .bond_order_system import BondOrderSystem
35
from .system import LabeledSystem, MultiSystems, System

dpdata/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from dpdata.cli import dpdata_cli
24

35
if __name__ == "__main__":

dpdata/abacus/md.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
import warnings
35

dpdata/abacus/relax.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24

35
import numpy as np

0 commit comments

Comments
 (0)