diff --git a/dpdata/cli.py b/dpdata/cli.py index ef6eeab77..2b33f9590 100644 --- a/dpdata/cli.py +++ b/dpdata/cli.py @@ -1,5 +1,6 @@ """Command line interface for dpdata.""" import argparse +from typing import Optional from . import __version__ from .system import System, LabeledSystem, MultiSystems @@ -47,11 +48,11 @@ def dpdata_cli(): def convert(*, from_file: str, from_format: str = "auto", - to_file: str = None, - to_format: str = None, + to_file: Optional[str] = None, + to_format: Optional[str] = None, no_labeled: bool = False, multi: bool = False, - type_map: list = None, + type_map: Optional[list] = None, **kwargs): """Convert files from one format to another one. diff --git a/dpdata/deepmd/hdf5.py b/dpdata/deepmd/hdf5.py index 8bbd00484..0e807f058 100644 --- a/dpdata/deepmd/hdf5.py +++ b/dpdata/deepmd/hdf5.py @@ -1,5 +1,5 @@ """Utils for deepmd/hdf5 format.""" -from typing import Union +from typing import Optional, Union import h5py import numpy as np @@ -11,7 +11,7 @@ def to_system_data(f: Union[h5py.File, h5py.Group], folder: str, - type_map: list = None, + type_map: Optional[list] = None, labels: bool = True) : """Load a HDF5 file. diff --git a/dpdata/gaussian/gjf.py b/dpdata/gaussian/gjf.py index 588f1ed67..727732b86 100644 --- a/dpdata/gaussian/gjf.py +++ b/dpdata/gaussian/gjf.py @@ -3,7 +3,7 @@ # under LGPL 3.0 license """Generate Gaussian input file.""" -from typing import List, Tuple, Union +from typing import Optional, List, Tuple, Union import uuid import itertools import warnings @@ -107,8 +107,8 @@ def make_gaussian_input( multiplicity: Union[str ,int] = "auto", charge: int = 0, fragment_guesses: bool = False, - basis_set: str = None, - keywords_high_multiplicity: str = None, + basis_set: Optional[str] = None, + keywords_high_multiplicity: Optional[str] = None, nproc: int = 1, ) -> str: """Make gaussian input file. diff --git a/dpdata/plugins/ase.py b/dpdata/plugins/ase.py index 728df3298..fa2093e40 100644 --- a/dpdata/plugins/ase.py +++ b/dpdata/plugins/ase.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Type +from typing import Optional, TYPE_CHECKING, Type from dpdata.driver import Driver, Minimizer from dpdata.format import Format import numpy as np @@ -93,7 +93,7 @@ def from_labeled_system(self, atoms: "ase.Atoms", **kwargs) -> dict: info_dict['virials'] = virials return info_dict - def from_multi_systems(self, file_name: str, begin: int=None, end: int=None, step: int=None, ase_fmt: str=None, **kwargs) -> "ase.Atoms": + def from_multi_systems(self, file_name: str, begin: Optional[int] = None, end: Optional[int] = None, step: Optional[int] = None, ase_fmt: Optional[str] = None, **kwargs) -> "ase.Atoms": """Convert a ASE supported file to ASE Atoms. It will finally be converted to MultiSystems. @@ -228,9 +228,9 @@ class ASEMinimizer(Minimizer): """ def __init__(self, driver: Driver, - optimizer: Type["Optimizer"] = None, + optimizer: Optional[Type["Optimizer"]] = None, fmax: float = 5e-3, - max_steps: int = None, + max_steps: Optional[int] = None, optimizer_kwargs: dict = {}) -> None: self.calculator = driver.ase_calculator if optimizer is None: diff --git a/dpdata/plugins/deepmd.py b/dpdata/plugins/deepmd.py index aa69c44b8..c3b7f4ca5 100644 --- a/dpdata/plugins/deepmd.py +++ b/dpdata/plugins/deepmd.py @@ -1,4 +1,4 @@ -from typing import Union, List +from typing import Optional, Union, List import dpdata import dpdata.deepmd.raw @@ -108,7 +108,7 @@ def _from_system(self, file_name: Union[str, h5py.Group, h5py.File], type_map: L def from_system(self, file_name: Union[str, h5py.Group, h5py.File], - type_map: List[str]=None, + type_map: Optional[List[str]] = None, **kwargs) -> dict: """Convert HDF5 file to System data. @@ -134,7 +134,7 @@ def from_system(self, def from_labeled_system(self, file_name: Union[str, h5py.Group, h5py.File], - type_map: List[str]=None, + type_map: Optional[List[str]] = None, **kwargs) -> dict: """Convert HDF5 file to LabeledSystem data.