Skip to content

Commit

Permalink
style: cleanup unreachable code
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan committed Dec 11, 2024
1 parent e1c8caf commit cb5cf49
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
args: [ --fix, --show-fixes ]
# Run the formatter.
- id: ruff-format

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ plugins = ["numpy.typing.mypy_plugin"]
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true
allow_redefinition = true
check_untyped_defs = false
exclude = [
Expand Down
3 changes: 0 additions & 3 deletions src/erlab/accessors/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@ def __call__(
if parallel_kw is None:
parallel_kw = {}

if kwargs is None:
kwargs = {}

is_dask: bool = not (
self._obj.chunksizes is None or len(self._obj.chunksizes) == 0
)
Expand Down
3 changes: 0 additions & 3 deletions src/erlab/interactive/imagetool/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,9 +1013,6 @@ def apply_func(self, func: Callable[[xr.DataArray], xr.DataArray] | None) -> Non
"""
# self._data is original data passed to `set_data`
# self.data is the current data transformed by ArraySlicer
if self._data is None:
return

self._applied_func = func

if self._applied_func is None:
Expand Down
6 changes: 3 additions & 3 deletions src/erlab/interactive/imagetool/slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def set_bins(

@QtCore.Slot(int, int, int, bool, result=list)
def set_bin(
self, cursor: int, axis: int, value: int, update: bool = True
self, cursor: int, axis: int, value: int | None, update: bool = True
) -> list[int]:
if value is None:
return []
Expand Down Expand Up @@ -639,7 +639,7 @@ def set_indices(self, cursor: int, value: list[int], update: bool = True) -> Non

@QtCore.Slot(int, int, int, bool, result=list)
def set_index(
self, cursor: int, axis: int, value: int, update: bool = True
self, cursor: int, axis: int, value: int | None, update: bool = True
) -> list[int | None]:
if value is None:
return []
Expand Down Expand Up @@ -696,7 +696,7 @@ def set_value(
self,
cursor: int,
axis: int,
value: float,
value: float | None,
update: bool = True,
uniform: bool = False,
) -> list[int | None]:
Expand Down
9 changes: 5 additions & 4 deletions src/erlab/interactive/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def fixed(self):
return self.check.isChecked()
return False

def setFixed(self, value: bool) -> None:
def setFixed(self, value: bool | QtCore.Qt.CheckState) -> None:
if isinstance(value, QtCore.Qt.CheckState):
if value == QtCore.Qt.CheckState.Unchecked:
value = False
Expand Down Expand Up @@ -1064,10 +1064,11 @@ def getMenu(self):
return self.menu

def getPlotItem(self) -> pg.PlotItem | None:
p = self
p: Self | None = self
while True:
try:
p = p.parentItem()
if p is not None:
p = p.parentItem()
except RuntimeError:
return None
if p is None:
Expand Down Expand Up @@ -1685,7 +1686,7 @@ def __init__(
raise ValueError("Orientation must be 'vertical' or 'horizontal'.")
self.cut_to_data = cut_to_data

self.input: None | xr.DataArray = None
self.input: None | xr.DataArray | npt.NDArray = None

self.initialize_layout(num_ax)

Expand Down
5 changes: 1 addition & 4 deletions src/erlab/plotting/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def label_subplots_nature(
| Literal[
"xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"
]
) = 8,
) = "medium",
**kwargs,
) -> None:
r"""Labels subplots with automatically generated labels.
Expand Down Expand Up @@ -672,9 +672,6 @@ def label_subplots_nature(
trans = matplotlib.transforms.ScaledTranslation(
offset[0] / 72, offset[1] / 72, axlist[i].get_figure().dpi_scale_trans
)

if fontsize is None:
fontsize = "medium"
axlist[i].figure.text(
# axlist[i].text(
0.0,
Expand Down
8 changes: 0 additions & 8 deletions src/erlab/plotting/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ def plot_array(
if func_args is None:
func_args = {}

if isinstance(arr, np.ndarray):
arr = xr.DataArray(arr)
if arr.ndim != 2:
raise ValueError("Input array must be 2D")

Expand Down Expand Up @@ -516,12 +514,6 @@ def plot_array_2d(
if normalize_with_larr:
carr = carr / larr

if lnorm is None:
lnorm = plt.Normalize()

if cnorm is None:
cnorm = plt.Normalize()

cmap_img, img = gen_2d_colormap(
larr.values,
carr.values,
Expand Down
14 changes: 9 additions & 5 deletions src/erlab/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@

def _convert_to_native(obj: list[Any]) -> list[Any]:
"""Convert a nested list of numpy objects to native types."""
if isinstance(obj, np.generic):
return obj.item()
if isinstance(obj, list):
return [_convert_to_native(item) for item in obj]
return obj

def _convert(obj: Any) -> Any:
if isinstance(obj, np.generic):
return obj.item()
if isinstance(obj, list):
return [_convert(item) for item in obj]
return obj

return _convert(obj)


def _find_stack_level() -> int:
Expand Down

0 comments on commit cb5cf49

Please sign in to comment.