Skip to content

Commit 7db1b4c

Browse files
authored
add Optional to type hints when default is None (#382)
Signed-off-by: Jinzhe Zeng <[email protected]> Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent efbaae6 commit 7db1b4c

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

dpdata/cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Command line interface for dpdata."""
22
import argparse
3+
from typing import Optional
34

45
from . import __version__
56
from .system import System, LabeledSystem, MultiSystems
@@ -47,11 +48,11 @@ def dpdata_cli():
4748
def convert(*,
4849
from_file: str,
4950
from_format: str = "auto",
50-
to_file: str = None,
51-
to_format: str = None,
51+
to_file: Optional[str] = None,
52+
to_format: Optional[str] = None,
5253
no_labeled: bool = False,
5354
multi: bool = False,
54-
type_map: list = None,
55+
type_map: Optional[list] = None,
5556
**kwargs):
5657
"""Convert files from one format to another one.
5758

dpdata/deepmd/hdf5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Utils for deepmd/hdf5 format."""
2-
from typing import Union
2+
from typing import Optional, Union
33

44
import h5py
55
import numpy as np
@@ -11,7 +11,7 @@
1111

1212
def to_system_data(f: Union[h5py.File, h5py.Group],
1313
folder: str,
14-
type_map: list = None,
14+
type_map: Optional[list] = None,
1515
labels: bool = True) :
1616
"""Load a HDF5 file.
1717

dpdata/gaussian/gjf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# under LGPL 3.0 license
44
"""Generate Gaussian input file."""
55

6-
from typing import List, Tuple, Union
6+
from typing import Optional, List, Tuple, Union
77
import uuid
88
import itertools
99
import warnings
@@ -107,8 +107,8 @@ def make_gaussian_input(
107107
multiplicity: Union[str ,int] = "auto",
108108
charge: int = 0,
109109
fragment_guesses: bool = False,
110-
basis_set: str = None,
111-
keywords_high_multiplicity: str = None,
110+
basis_set: Optional[str] = None,
111+
keywords_high_multiplicity: Optional[str] = None,
112112
nproc: int = 1,
113113
) -> str:
114114
"""Make gaussian input file.

dpdata/plugins/ase.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Type
1+
from typing import Optional, TYPE_CHECKING, Type
22
from dpdata.driver import Driver, Minimizer
33
from dpdata.format import Format
44
import numpy as np
@@ -93,7 +93,7 @@ def from_labeled_system(self, atoms: "ase.Atoms", **kwargs) -> dict:
9393
info_dict['virials'] = virials
9494
return info_dict
9595

96-
def from_multi_systems(self, file_name: str, begin: int=None, end: int=None, step: int=None, ase_fmt: str=None, **kwargs) -> "ase.Atoms":
96+
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":
9797
"""Convert a ASE supported file to ASE Atoms.
9898
9999
It will finally be converted to MultiSystems.
@@ -228,9 +228,9 @@ class ASEMinimizer(Minimizer):
228228
"""
229229
def __init__(self,
230230
driver: Driver,
231-
optimizer: Type["Optimizer"] = None,
231+
optimizer: Optional[Type["Optimizer"]] = None,
232232
fmax: float = 5e-3,
233-
max_steps: int = None,
233+
max_steps: Optional[int] = None,
234234
optimizer_kwargs: dict = {}) -> None:
235235
self.calculator = driver.ase_calculator
236236
if optimizer is None:

dpdata/plugins/deepmd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Union, List
1+
from typing import Optional, Union, List
22

33
import dpdata
44
import dpdata.deepmd.raw
@@ -108,7 +108,7 @@ def _from_system(self, file_name: Union[str, h5py.Group, h5py.File], type_map: L
108108

109109
def from_system(self,
110110
file_name: Union[str, h5py.Group, h5py.File],
111-
type_map: List[str]=None,
111+
type_map: Optional[List[str]] = None,
112112
**kwargs) -> dict:
113113
"""Convert HDF5 file to System data.
114114
@@ -134,7 +134,7 @@ def from_system(self,
134134

135135
def from_labeled_system(self,
136136
file_name: Union[str, h5py.Group, h5py.File],
137-
type_map: List[str]=None,
137+
type_map: Optional[List[str]] = None,
138138
**kwargs) -> dict:
139139
"""Convert HDF5 file to LabeledSystem data.
140140

0 commit comments

Comments
 (0)