From 55300f366ee6a230747b423ec3a00a57bfbd21c1 Mon Sep 17 00:00:00 2001 From: BO ZHANG Date: Sat, 28 Oct 2023 13:56:36 +0800 Subject: [PATCH] fix docstring and typing --- csst_proto/config.py | 2 +- csst_proto/demo.py | 6 +++--- csst_proto/flip_image.py | 2 +- csst_proto/flip_image_in_parallel.py | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/csst_proto/config.py b/csst_proto/config.py index 1180e5f..d32fcd4 100644 --- a/csst_proto/config.py +++ b/csst_proto/config.py @@ -24,7 +24,7 @@ HERE: str = os.path.dirname(__file__) # 这个函数演示了如何利用随包数据 # 当config_path被指定时,会读取指定的config_path # 当config_path=None时,读取随包数据中的config/default_config.toml -def read_config(config_path: Optional[str] = None): +def read_config(config_path: Optional[str] = None) -> dict: """ Get config info from a toml file. diff --git a/csst_proto/demo.py b/csst_proto/demo.py index 89d5cb0..f75f4ec 100644 --- a/csst_proto/demo.py +++ b/csst_proto/demo.py @@ -11,7 +11,7 @@ Modified-History: from typing import Any -def demo_function(*args: Any): +def demo_function(*args: Any) -> int: """ A demo function. @@ -66,9 +66,9 @@ class DemoClass: >>> a.say_hello() """ - def __init__(self, first_name, last_name): + def __init__(self, first_name, last_name) -> None: self.first_name = first_name self.last_name = last_name - def say_hello(self): + def say_hello(self) -> None: print("Hello, {} {}!".format(self.first_name, self.last_name)) diff --git a/csst_proto/flip_image.py b/csst_proto/flip_image.py index a95d4a3..9b46246 100644 --- a/csst_proto/flip_image.py +++ b/csst_proto/flip_image.py @@ -61,7 +61,7 @@ def flip_image(image: np.ndarray, use_numpy: bool = False) -> np.ndarray: # 此函数读取了随包数据中的test_image.txt -def read_default_image(): +def read_default_image() -> np.ndarray: """ Read default image. diff --git a/csst_proto/flip_image_in_parallel.py b/csst_proto/flip_image_in_parallel.py index dc35acb..8f78572 100644 --- a/csst_proto/flip_image_in_parallel.py +++ b/csst_proto/flip_image_in_parallel.py @@ -30,7 +30,8 @@ def flip_multiple_images_mp(images: list[np.ndarray], n_jobs: int) -> list[np.nd Returns ------- - The flipped image list. + list[np.ndarray] + The flipped image list. """ with multiprocessing.Pool(n_jobs) as p: results = p.map(flip_image, images) @@ -52,7 +53,8 @@ def flip_multiple_images_jl(images: list[np.ndarray], n_jobs: int) -> list[np.nd Returns ------- - The flipped image list. + list[np.ndarray] + The flipped image list. """ return joblib.Parallel(n_jobs=n_jobs, backend="multiprocessing")( joblib.delayed(flip_image)(image) for image in images -- GitLab