Skip to content

Commit

Permalink
👌 Improved typing where dict and list were used w/o types
Browse files Browse the repository at this point in the history
  • Loading branch information
s-weigand committed Nov 21, 2021
1 parent 9402e55 commit 5172afa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion glotaran/parameter/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def from_list_or_value(
return param

@classmethod
def from_dict(cls, parameter_dict: dict) -> Parameter:
def from_dict(cls, parameter_dict: dict[str, Parameter]) -> Parameter:
"""Create a :class:`Parameter` from a dictionary.
Expects a dictionary created by :method:`Parameter.as_dict`.
Expand Down
15 changes: 8 additions & 7 deletions glotaran/parameter/parameter_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from copy import copy
from textwrap import indent
from typing import TYPE_CHECKING
from typing import Any
from typing import Generator

import asteval
Expand Down Expand Up @@ -69,7 +70,7 @@ def __init__(self, label: str = None, root_group: ParameterGroup = None):
@classmethod
def from_dict(
cls,
parameter_dict: dict[str, dict | list],
parameter_dict: dict[str, dict[str, Any] | list[float | list[Any]]],
label: str = None,
root_group: ParameterGroup = None,
) -> ParameterGroup:
Expand Down Expand Up @@ -103,15 +104,15 @@ def from_dict(
@classmethod
def from_list(
cls,
parameter_list: list[float | list],
parameter_list: list[float | list[Any]],
label: str = None,
root_group: ParameterGroup = None,
) -> ParameterGroup:
"""Create a :class:`ParameterGroup` from a list.
Parameters
----------
parameter_list : list[float | list]
parameter_list : list[float | list[Any]]
A parameter list containing parameters
label : str
The label of the group.
Expand Down Expand Up @@ -147,12 +148,12 @@ def from_list(
return root

@classmethod
def from_parameter_dict_list(cls, parameter_dict_list: list[dict]) -> ParameterGroup:
def from_parameter_dict_list(cls, parameter_dict_list: list[dict[str, Any]]) -> ParameterGroup:
"""Create a :class:`ParameterGroup` from a list of parameter dictionaries.
Parameters
----------
parameter_dict_list : list[dict]
parameter_dict_list : list[dict[str, Any]]
A list of parameter dictionaries.
Returns
Expand Down Expand Up @@ -232,7 +233,7 @@ def root_group(self) -> ParameterGroup | None:
"""
return self._root_group

def to_parameter_dict_list(self, as_optimized: bool = True) -> list[dict]:
def to_parameter_dict_list(self, as_optimized: bool = True) -> list[dict[str, Any]]:
"""Create list of parameter dictionaries from the group.
Parameters
Expand All @@ -242,7 +243,7 @@ def to_parameter_dict_list(self, as_optimized: bool = True) -> list[dict]:
Returns
-------
list[dict]
list[dict[str, Any]]
Alist of parameter dictionaries.
"""
return [p[1].as_dict(as_optimized=as_optimized) for p in self.all()]
Expand Down

0 comments on commit 5172afa

Please sign in to comment.