From 1b4c59ed62d3ec29d3bb0a91e019a6b69429d5d7 Mon Sep 17 00:00:00 2001 From: yzx9 Date: Thu, 22 Aug 2024 01:43:28 +0800 Subject: [PATCH] type: mark types of `extra_repr` returns --- swcgeom/transforms/base.py | 4 ++-- swcgeom/transforms/branch.py | 4 ++-- swcgeom/transforms/geometry.py | 14 +++++++------- swcgeom/transforms/image_stack.py | 2 +- swcgeom/transforms/tree.py | 6 +++--- swcgeom/transforms/tree_assembler.py | 8 ++++---- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/swcgeom/transforms/base.py b/swcgeom/transforms/base.py index de89489..71bb7d9 100644 --- a/swcgeom/transforms/base.py +++ b/swcgeom/transforms/base.py @@ -33,7 +33,7 @@ def __repr__(self) -> str: repr_ = self.extra_repr() return f"{classname}({repr_})" - def extra_repr(self): + def extra_repr(self) -> str: """Provides a human-friendly representation of the module. This method extends the basic string representation provided by @@ -48,7 +48,7 @@ class Foo(Transform[T, K]): def __init__(self, my_parameter: int = 1): self.my_parameter = my_parameter - def extra_repr(self): + def extra_repr(self) -> str: return f"my_parameter={self.my_parameter}" Notes diff --git a/swcgeom/transforms/branch.py b/swcgeom/transforms/branch.py index bb7ae47..1d6c1a3 100644 --- a/swcgeom/transforms/branch.py +++ b/swcgeom/transforms/branch.py @@ -72,7 +72,7 @@ def resample(self, xyzr: npt.NDArray[np.float32]) -> npt.NDArray[np.float32]: r = np.interp(xvals, xp, xyzr[:, 3]) return cast(npt.NDArray[np.float32], np.stack([x, y, z, r], axis=1)) - def extra_repr(self): + def extra_repr(self) -> str: return f"n_nodes={self.n_nodes}" @@ -100,7 +100,7 @@ def __call__(self, x: Branch) -> Branch[DictSWC]: return x - def extra_repr(self): + def extra_repr(self) -> str: return f"n_nodes={self.n_nodes}" diff --git a/swcgeom/transforms/geometry.py b/swcgeom/transforms/geometry.py index cfe6fd2..945cf2c 100644 --- a/swcgeom/transforms/geometry.py +++ b/swcgeom/transforms/geometry.py @@ -72,7 +72,7 @@ def __call__(self, x: T) -> T: new_tree.ndata[new_tree.names.r] = r return new_tree - def extra_repr(self): + def extra_repr(self) -> str: return f"r={self.r:.4f}" @@ -141,7 +141,7 @@ def __init__(self, tx: float, ty: float, tz: float, **kwargs) -> None: super().__init__(translate3d(tx, ty, tz), **kwargs) self.tx, self.ty, self.tz = tx, ty, tz - def extra_repr(self): + def extra_repr(self) -> str: return f"tx={self.tx:.4f}, ty={self.ty:.4f}, tz={self.tz:.4f}" @classmethod @@ -194,8 +194,8 @@ def __init__( self.theta = theta self.center = center - def extra_repr(self): - return f"n={self.n}, theta={self.theta:.4f}, center={self.center}" # TODO: imporve format of n + def extra_repr(self) -> str: + return f"n={self.n}, theta={self.theta:.4f}, center={self.center}" # TODO: improve format of n @classmethod def transform( @@ -216,7 +216,7 @@ def __init__(self, theta: float, center: Center = "root", **kwargs) -> None: super().__init__(rotate3d_x(theta), center=center, **kwargs) self.theta = theta - def extra_repr(self): + def extra_repr(self) -> str: return f"center={self.center}, theta={self.theta:.4f}" @classmethod @@ -232,7 +232,7 @@ def __init__(self, theta: float, center: Center = "root", **kwargs) -> None: self.theta = theta self.center = center - def extra_repr(self): + def extra_repr(self) -> str: return f"theta={self.theta:.4f}, center={self.center}" @classmethod @@ -248,7 +248,7 @@ def __init__(self, theta: float, center: Center = "root", **kwargs) -> None: self.theta = theta self.center = center - def extra_repr(self): + def extra_repr(self) -> str: return f"theta={self.theta:.4f}, center={self.center}" @classmethod diff --git a/swcgeom/transforms/image_stack.py b/swcgeom/transforms/image_stack.py index afefdb3..d550a06 100644 --- a/swcgeom/transforms/image_stack.py +++ b/swcgeom/transforms/image_stack.py @@ -136,7 +136,7 @@ def transform_population( if not os.path.isfile(tif): self.transform_and_save(tif, tree, verbose=False) - def extra_repr(self): + def extra_repr(self) -> str: res = ",".join(f"{a:.4f}" for a in self.resolution) return f"resolution=({res})" diff --git a/swcgeom/transforms/tree.py b/swcgeom/transforms/tree.py index 4b861d9..e04e6ed 100644 --- a/swcgeom/transforms/tree.py +++ b/swcgeom/transforms/tree.py @@ -65,7 +65,7 @@ def __call__(self, x: Tree) -> Tree: return x - def extra_repr(self): + def extra_repr(self) -> str: return f"n_nodes={self.n_nodes}" @@ -104,7 +104,7 @@ def leave(n: Tree.Node, keep_children: list[bool]) -> bool: y = to_subtree(x, removals) return y - def extra_repr(self): + def extra_repr(self) -> str: return f"type={self.type}" @@ -195,7 +195,7 @@ def __call__(self, x: Tree) -> Tree: self.callbacks.pop() return to_subtree(x, removals) - def extra_repr(self): + def extra_repr(self) -> str: return f"threshold={self.thre}" def _leave( diff --git a/swcgeom/transforms/tree_assembler.py b/swcgeom/transforms/tree_assembler.py index 726b7aa..acbf81f 100644 --- a/swcgeom/transforms/tree_assembler.py +++ b/swcgeom/transforms/tree_assembler.py @@ -38,7 +38,7 @@ def __init__(self, *, thre: float = 0.2, undirected: bool = True): def __call__( self, lines: Iterable[pd.DataFrame], *, names: Optional[SWCNames] = None - ): + ): # TODO check this return self.assemble(lines, names=names) def assemble( @@ -56,8 +56,8 @@ def assemble( Parameters ---------- lines : List of ~pd.DataFrame - An array of tables containing a line, columns should follwing - the swc. + An array of tables containing a line, columns should + following the swc. undirected : bool, default `True` Forwarding to `self.try_assemble`. names : SWCNames, optional @@ -170,5 +170,5 @@ def try_assemble( return tree, lines - def extra_repr(self): + def extra_repr(self) -> str: return f"thre={self.thre}, undirected={self.undirected}"