chore: update resolvers to modern typing syntax

This commit is contained in:
Matthias
2024-10-04 07:02:57 +02:00
parent d8e41fa8b1
commit b8bbf3b69e
4 changed files with 17 additions and 17 deletions

View File

@@ -4,7 +4,7 @@ This module loads custom exchanges
import logging
from inspect import isclass
from typing import Any, Dict, List, Optional
from typing import Any, Optional
import freqtrade.exchange as exchanges
from freqtrade.constants import Config, ExchangeConfig
@@ -90,7 +90,7 @@ class ExchangeResolver(IResolver):
@classmethod
def search_all_objects(
cls, config: Config, enum_failed: bool, recursive: bool = False
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""
Searches for valid objects
:param config: Config object

View File

@@ -8,8 +8,9 @@ import importlib.util
import inspect
import logging
import sys
from collections.abc import Iterator
from pathlib import Path
from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union
from typing import Any, Optional, Union
from freqtrade.constants import Config
from freqtrade.exceptions import OperationalException
@@ -40,7 +41,7 @@ class IResolver:
"""
# Childclasses need to override this
object_type: Type[Any]
object_type: type[Any]
object_type_str: str
user_subdir: Optional[str] = None
initial_search_path: Optional[Path] = None
@@ -52,9 +53,9 @@ class IResolver:
cls,
config: Config,
user_subdir: Optional[str] = None,
extra_dirs: Optional[List[str]] = None,
) -> List[Path]:
abs_paths: List[Path] = []
extra_dirs: Optional[list[str]] = None,
) -> list[Path]:
abs_paths: list[Path] = []
if cls.initial_search_path:
abs_paths.append(cls.initial_search_path)
@@ -124,7 +125,7 @@ class IResolver:
@classmethod
def _search_object(
cls, directory: Path, *, object_name: str, add_source: bool = False
) -> Union[Tuple[Any, Path], Tuple[None, None]]:
) -> Union[tuple[Any, Path], tuple[None, None]]:
"""
Search for the objectname in the given directory
:param directory: relative or absolute directory path
@@ -153,7 +154,7 @@ class IResolver:
@classmethod
def _load_object(
cls, paths: List[Path], *, object_name: str, add_source: bool = False, kwargs: Dict
cls, paths: list[Path], *, object_name: str, add_source: bool = False, kwargs: dict
) -> Optional[Any]:
"""
Try to load object from path list.
@@ -188,7 +189,7 @@ class IResolver:
:return: Object instance or None
"""
extra_dirs: List[str] = []
extra_dirs: list[str] = []
if extra_dir:
extra_dirs.append(extra_dir)
@@ -207,7 +208,7 @@ class IResolver:
@classmethod
def search_all_objects(
cls, config: Config, enum_failed: bool, recursive: bool = False
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""
Searches for valid objects
:param config: Config object
@@ -239,7 +240,7 @@ class IResolver:
enum_failed: bool,
recursive: bool = False,
basedir: Optional[Path] = None,
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""
Searches a directory for valid objects
:param directory: Path to search
@@ -249,7 +250,7 @@ class IResolver:
:return: List of dicts containing 'name', 'class' and 'location' entries
"""
logger.debug(f"Searching for {cls.object_type.__name__} '{directory}'")
objects: List[Dict[str, Any]] = []
objects: list[dict[str, Any]] = []
if not directory.is_dir():
logger.info(f"'{directory}' is not a directory, skipping.")
return objects

View File

@@ -4,7 +4,6 @@ This module load custom pairlists
import logging
from pathlib import Path
from typing import Dict
from freqtrade.constants import Config
from freqtrade.plugins.protections import IProtection
@@ -26,7 +25,7 @@ class ProtectionResolver(IResolver):
@staticmethod
def load_protection(
protection_name: str, config: Config, protection_config: Dict
protection_name: str, config: Config, protection_config: dict
) -> IProtection:
"""
Load the protection with protection_name

View File

@@ -10,7 +10,7 @@ from base64 import urlsafe_b64decode
from inspect import getfullargspec
from os import walk
from pathlib import Path
from typing import Any, List, Optional
from typing import Any, Optional
from freqtrade.configuration.config_validation import validate_migrated_strategy_settings
from freqtrade.constants import REQUIRED_ORDERTIF, REQUIRED_ORDERTYPES, USERPATH_STRATEGIES, Config
@@ -256,7 +256,7 @@ class StrategyResolver(IResolver):
:return: Strategy instance or None
"""
if config.get("recursive_strategy_search", False):
extra_dirs: List[str] = [
extra_dirs: list[str] = [
path[0] for path in walk(f"{config['user_data_dir']}/{USERPATH_STRATEGIES}")
] # sub-directories
else: