From a98474017ddaeeea27aec439b9c2993933440624 Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Fri, 11 Apr 2025 17:24:11 +0200 Subject: [PATCH 1/2] Replace `kwargs:dict` with `kwargs:any` --- pymoo/core/individual.py | 9 +++++---- pymoo/core/variable.py | 18 +++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pymoo/core/individual.py b/pymoo/core/individual.py index f5d9c2ae..58ce1e34 100644 --- a/pymoo/core/individual.py +++ b/pymoo/core/individual.py @@ -12,6 +12,7 @@ ] import copy +from typing import Any from typing import Optional from typing import Tuple from typing import Union @@ -48,7 +49,7 @@ class Individual: def __init__( self, config: Optional[dict] = None, - **kwargs: dict, + **kwargs: Any, ) -> None: """ Constructor for the ``Invididual`` class. @@ -58,7 +59,7 @@ def __init__( config : dict, None A dictionary of configuration metadata. If ``None``, use a class-dependent default configuration. - kwargs : dict + kwargs : Any Additional keyword arguments containing data which is to be stored in the ``Individual``. """ @@ -553,14 +554,14 @@ def feasible(self) -> np.ndarray: def set_by_dict( self, - **kwargs: dict + **kwargs: Any ) -> None: """ Set an individual's data or metadata using values in a dictionary. Parameters ---------- - kwargs : dict + kwargs : Any Keyword arguments defining the data to set. """ for k, v in kwargs.items(): diff --git a/pymoo/core/variable.py b/pymoo/core/variable.py index a8f1f5b3..728a75cd 100644 --- a/pymoo/core/variable.py +++ b/pymoo/core/variable.py @@ -13,7 +13,7 @@ "get", ] -from typing import Optional, Tuple +from typing import Any, Optional, Tuple from typing import Union import numpy as np from numpy.typing import ArrayLike @@ -111,14 +111,14 @@ def set( def get( self, - **kwargs: dict + **kwargs: Any ) -> object: """ Get the value of a decision variable. Parameters ---------- - kwargs : dict + kwargs : Any Additional keyword arguments. Returns @@ -139,7 +139,7 @@ def __init__( value: Optional[object] = None, bounds: Tuple[Optional[object],Optional[object]] = (None, None), strict: Optional[Tuple[Optional[object],Optional[object]]] = None, - **kwargs: dict, + **kwargs: Any, ) -> None: """ Constructor for the ``BoundedVariable`` class. @@ -154,7 +154,7 @@ def __init__( strict : tuple, None Strict boundaries for the decision variable. If ``None``, the value of ``bounds`` is copied to ``strict``. - kwargs : dict + kwargs : Any Additional keyword arguments for ``active`` and ``flag``. """ # call the Variable constructor @@ -302,7 +302,7 @@ def __init__( value: Optional[object] = None, options: Optional[ArrayLike] = None, all: Optional[ArrayLike] = None, - **kwargs: dict, + **kwargs: Any, ) -> None: """ Constructor for the ``Choice`` class. @@ -316,7 +316,7 @@ def __init__( all : ArrayLike, None A strict list of decision variable options from which to choose. If ``None``, the value of ``options`` is copied to ``all``. - kwargs : dict + kwargs : Any Additional keyword arguments for ``active`` and ``flag``. """ # all super constructor @@ -357,7 +357,7 @@ def _sample( def get( *args: Tuple[Union[Variable,object],...], size: Optional[Union[tuple,int]] = None, - **kwargs: dict + **kwargs: Any ) -> Union[tuple,object,None]: """ Get decision variable values from a tuple of ``Variable`` objects. @@ -368,7 +368,7 @@ def get( A tuple of ``Variable`` or ``object``s. size : tuple, int, None Size to reshape decision variables. - kwargs : dict + kwargs : Any Additional keyword arguments to pass to the ``get`` method of the ``Variable`` class when getting decision variable values. From e25a27176c0784d342dfa79a128c01f2fa3c35bd Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Fri, 11 Apr 2025 19:23:27 +0200 Subject: [PATCH 2/2] Args: Tuple[str] -> str --- pymoo/core/individual.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pymoo/core/individual.py b/pymoo/core/individual.py index 58ce1e34..c200d825 100644 --- a/pymoo/core/individual.py +++ b/pymoo/core/individual.py @@ -595,15 +595,15 @@ def set( def get( self, - *keys: Tuple[str,...], + *keys: str, ) -> Union[tuple,object]: """ Get the values for one or more keys for an individual. Parameters ---------- - keys : tuple - A tuple of keys for which to get values. + keys : str + Keys for which to get values. Returns -------