Skip to content

Commit

Permalink
💬 update type hints
Browse files Browse the repository at this point in the history
the number of ruff errors is 1872.
  • Loading branch information
arafune committed Oct 5, 2023
1 parent 9db5896 commit 0dbc6bc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
4 changes: 3 additions & 1 deletion arpes/analysis/band_analysis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
if TYPE_CHECKING:
from collections.abc import Callable

from lmfit import lf


class ParamType(NamedTuple):
"""Parameter type."""
Expand All @@ -16,7 +18,7 @@ class ParamType(NamedTuple):
stderr: float


def param_getter(param_name: ParamType, *, safe: bool = True) -> Callabe[..., float]:
def param_getter(param_name: ParamType, *, safe: bool = True) -> Callable[..., float]:
"""Constructs a function to extract a parameter value by name.
Useful to extract data from inside an array of `lmfit.ModelResult` instances.
Expand Down
2 changes: 1 addition & 1 deletion arpes/endstations/plugin/SPD_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Implements loading the itx and sp2 text file format for SPECS prodigy.""" # noqa: N999
"""Implements loading the itx and sp2 text file format for SPECS prodigy."""
from __future__ import annotations

from pathlib import Path
Expand Down
6 changes: 3 additions & 3 deletions arpes/utilities/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def wrap_tqdm(
return tqdm(x, *args, **kwargs)


def get_full_notebook_information() -> dict | None:
def get_full_notebook_information() -> dict[str, Incomplete] | None:
"""Javascriptless method to fetch current Jupyter sessions and the one matching this kernel."""
try: # Respect those that opt not to use IPython
import ipykernel
Expand All @@ -79,7 +79,7 @@ def get_full_notebook_information() -> dict | None:
"server": server,
"session": sess,
}
except:
except (KeyError, TypeError):
pass
return None

Expand All @@ -94,7 +94,7 @@ def get_notebook_name() -> str | None:
can only return None.
"""
jupyter_info = get_full_notebook_information()

assert isinstance(jupyter_info, dict)
try:
return jupyter_info["session"]["notebook"]["name"].split(".")[0]
except (KeyError, TypeError):
Expand Down
21 changes: 14 additions & 7 deletions arpes/utilities/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):


@ui_builder
def layout(*children, layout_cls=None, widget=None) -> QWidget:
def layout(*children, layout_cls: type | None = None, widget=None) -> QWidget:
"""A convenience method for constructing a layout and a parent widget."""
if layout_cls is None:
layout_cls = QGridLayout
Expand Down Expand Up @@ -243,7 +243,7 @@ def splitter(first, second, direction=Qt.Vertical, size=None) -> QWidget:


@ui_builder
def group(*args, label=None, layout_cls=None) -> QWidget:
def group(*args, label=None, layout_cls: type | None = None) -> QWidget:
"""A convenience method for making a GroupBox container."""
if args and isinstance(args[0], str):
label = args[0]
Expand Down Expand Up @@ -335,7 +335,14 @@ def slider(minimum=0, maximum=10, interval: float = 0, *, horizontal: bool = Tru


@ui_builder
def spin_box(minimum=0, maximum=10, step=1, adaptive=True, value=None) -> QWidget:
def spin_box(
minimum: float = 0,
maximum: float = 10,
step: float = 1,
value: Incomplete = None,
*,
adaptive: bool = True,
) -> QWidget:
"""A convenience method for making a SpinBox."""
widget = SubjectiveSpinBox()

Expand All @@ -353,17 +360,17 @@ def spin_box(minimum=0, maximum=10, step=1, adaptive=True, value=None) -> QWidge


@ui_builder
def text_edit(text="", *args: Incomplete) -> QWidget:
def text_edit(text: str = "", *args: Incomplete) -> QWidget:
"""A convenience method for making multiline TextEdit."""
return SubjectiveTextEdit(text, *args)


@ui_builder
def numeric_input(
value=0,
value: float = 0,
input_type: type = float,
*args: Incomplete,
validator_settings=None,
validator_settings: dict[str:float] | None = None,
) -> QWidget:
"""A numeric input with input validation."""
validators = {
Expand All @@ -384,7 +391,7 @@ def numeric_input(

if validator_settings is None:
validator_settings = default_settings.get(input_type)

assert isinstance(validator_settings, dict)
widget = SubjectiveLineEdit(str(value), *args)
widget.setValidator(validators.get(input_type, QtGui.QIntValidator)(**validator_settings))

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ ignore = [
"PD",
"ANN101",
"N806", # non-lowercase-variable-in-function
"N999", # invalid-module-name (N999)
"S101",
"PD011", # pandas-use-of-dot-values
"FBT002", # boolean-default-value-in-function-definition
Expand Down

0 comments on commit 0dbc6bc

Please sign in to comment.