chore: update resolvers to modern typing syntax
This commit is contained in:
@@ -4,7 +4,7 @@ This module loads custom exchanges
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from inspect import isclass
|
from inspect import isclass
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
import freqtrade.exchange as exchanges
|
import freqtrade.exchange as exchanges
|
||||||
from freqtrade.constants import Config, ExchangeConfig
|
from freqtrade.constants import Config, ExchangeConfig
|
||||||
@@ -90,7 +90,7 @@ class ExchangeResolver(IResolver):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def search_all_objects(
|
def search_all_objects(
|
||||||
cls, config: Config, enum_failed: bool, recursive: bool = False
|
cls, config: Config, enum_failed: bool, recursive: bool = False
|
||||||
) -> List[Dict[str, Any]]:
|
) -> list[dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Searches for valid objects
|
Searches for valid objects
|
||||||
:param config: Config object
|
:param config: Config object
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ import importlib.util
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
from collections.abc import Iterator
|
||||||
from pathlib import Path
|
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.constants import Config
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
@@ -40,7 +41,7 @@ class IResolver:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Childclasses need to override this
|
# Childclasses need to override this
|
||||||
object_type: Type[Any]
|
object_type: type[Any]
|
||||||
object_type_str: str
|
object_type_str: str
|
||||||
user_subdir: Optional[str] = None
|
user_subdir: Optional[str] = None
|
||||||
initial_search_path: Optional[Path] = None
|
initial_search_path: Optional[Path] = None
|
||||||
@@ -52,9 +53,9 @@ class IResolver:
|
|||||||
cls,
|
cls,
|
||||||
config: Config,
|
config: Config,
|
||||||
user_subdir: Optional[str] = None,
|
user_subdir: Optional[str] = None,
|
||||||
extra_dirs: Optional[List[str]] = None,
|
extra_dirs: Optional[list[str]] = None,
|
||||||
) -> List[Path]:
|
) -> list[Path]:
|
||||||
abs_paths: List[Path] = []
|
abs_paths: list[Path] = []
|
||||||
if cls.initial_search_path:
|
if cls.initial_search_path:
|
||||||
abs_paths.append(cls.initial_search_path)
|
abs_paths.append(cls.initial_search_path)
|
||||||
|
|
||||||
@@ -124,7 +125,7 @@ class IResolver:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _search_object(
|
def _search_object(
|
||||||
cls, directory: Path, *, object_name: str, add_source: bool = False
|
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
|
Search for the objectname in the given directory
|
||||||
:param directory: relative or absolute directory path
|
:param directory: relative or absolute directory path
|
||||||
@@ -153,7 +154,7 @@ class IResolver:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _load_object(
|
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]:
|
) -> Optional[Any]:
|
||||||
"""
|
"""
|
||||||
Try to load object from path list.
|
Try to load object from path list.
|
||||||
@@ -188,7 +189,7 @@ class IResolver:
|
|||||||
:return: Object instance or None
|
:return: Object instance or None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
extra_dirs: List[str] = []
|
extra_dirs: list[str] = []
|
||||||
if extra_dir:
|
if extra_dir:
|
||||||
extra_dirs.append(extra_dir)
|
extra_dirs.append(extra_dir)
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ class IResolver:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def search_all_objects(
|
def search_all_objects(
|
||||||
cls, config: Config, enum_failed: bool, recursive: bool = False
|
cls, config: Config, enum_failed: bool, recursive: bool = False
|
||||||
) -> List[Dict[str, Any]]:
|
) -> list[dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Searches for valid objects
|
Searches for valid objects
|
||||||
:param config: Config object
|
:param config: Config object
|
||||||
@@ -239,7 +240,7 @@ class IResolver:
|
|||||||
enum_failed: bool,
|
enum_failed: bool,
|
||||||
recursive: bool = False,
|
recursive: bool = False,
|
||||||
basedir: Optional[Path] = None,
|
basedir: Optional[Path] = None,
|
||||||
) -> List[Dict[str, Any]]:
|
) -> list[dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Searches a directory for valid objects
|
Searches a directory for valid objects
|
||||||
:param directory: Path to search
|
:param directory: Path to search
|
||||||
@@ -249,7 +250,7 @@ class IResolver:
|
|||||||
:return: List of dicts containing 'name', 'class' and 'location' entries
|
:return: List of dicts containing 'name', 'class' and 'location' entries
|
||||||
"""
|
"""
|
||||||
logger.debug(f"Searching for {cls.object_type.__name__} '{directory}'")
|
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():
|
if not directory.is_dir():
|
||||||
logger.info(f"'{directory}' is not a directory, skipping.")
|
logger.info(f"'{directory}' is not a directory, skipping.")
|
||||||
return objects
|
return objects
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ This module load custom pairlists
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
from freqtrade.constants import Config
|
from freqtrade.constants import Config
|
||||||
from freqtrade.plugins.protections import IProtection
|
from freqtrade.plugins.protections import IProtection
|
||||||
@@ -26,7 +25,7 @@ class ProtectionResolver(IResolver):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_protection(
|
def load_protection(
|
||||||
protection_name: str, config: Config, protection_config: Dict
|
protection_name: str, config: Config, protection_config: dict
|
||||||
) -> IProtection:
|
) -> IProtection:
|
||||||
"""
|
"""
|
||||||
Load the protection with protection_name
|
Load the protection with protection_name
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from base64 import urlsafe_b64decode
|
|||||||
from inspect import getfullargspec
|
from inspect import getfullargspec
|
||||||
from os import walk
|
from os import walk
|
||||||
from pathlib import Path
|
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.configuration.config_validation import validate_migrated_strategy_settings
|
||||||
from freqtrade.constants import REQUIRED_ORDERTIF, REQUIRED_ORDERTYPES, USERPATH_STRATEGIES, Config
|
from freqtrade.constants import REQUIRED_ORDERTIF, REQUIRED_ORDERTYPES, USERPATH_STRATEGIES, Config
|
||||||
@@ -256,7 +256,7 @@ class StrategyResolver(IResolver):
|
|||||||
:return: Strategy instance or None
|
:return: Strategy instance or None
|
||||||
"""
|
"""
|
||||||
if config.get("recursive_strategy_search", False):
|
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}")
|
path[0] for path in walk(f"{config['user_data_dir']}/{USERPATH_STRATEGIES}")
|
||||||
] # sub-directories
|
] # sub-directories
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user