diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 000000000..773c9e023 --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,12 @@ +version = 1 + +test_patterns = ["tests/test_*.py"] + +exclude_patterns = ["examples/**"] + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" diff --git a/qlib/contrib/evaluate_portfolio.py b/qlib/contrib/evaluate_portfolio.py index 04ddd8db0..b3a770e7c 100644 --- a/qlib/contrib/evaluate_portfolio.py +++ b/qlib/contrib/evaluate_portfolio.py @@ -61,7 +61,7 @@ def get_position_value(evaluate_date, position): # load close price for position # position should also consider cash instruments = list(position.keys()) - instruments = list(set(instruments) - set(["cash"])) # filter 'cash' + instruments = list(set(instruments) - {"cash"}) # filter 'cash' fields = ["$close"] close_data_df = D.features( instruments, @@ -80,7 +80,7 @@ def get_position_list_value(positions): instruments = set() for day, position in positions.items(): instruments.update(position.keys()) - instruments = list(set(instruments) - set(["cash"])) # filter 'cash' + instruments = list(set(instruments) - {"cash"}) # filter 'cash' instruments.sort() day_list = list(positions.keys()) day_list.sort() diff --git a/qlib/contrib/online/manager.py b/qlib/contrib/online/manager.py index b0be7f076..70b7bad40 100644 --- a/qlib/contrib/online/manager.py +++ b/qlib/contrib/online/manager.py @@ -63,7 +63,7 @@ class UserManager: account_path = self.data_path / user_id strategy_file = self.data_path / user_id / "strategy_{}.pickle".format(user_id) model_file = self.data_path / user_id / "model_{}.pickle".format(user_id) - cur_user_list = [user_id for user_id in self.users] + cur_user_list = list(self.users) if user_id in cur_user_list: raise ValueError("User {} has been loaded".format(user_id)) else: diff --git a/qlib/contrib/report/graph.py b/qlib/contrib/report/graph.py index 70e382fb1..677e767ee 100644 --- a/qlib/contrib/report/graph.py +++ b/qlib/contrib/report/graph.py @@ -161,7 +161,7 @@ class DistplotGraph(BaseGraph): """ _t_df = self._df.dropna() _data_list = [_t_df[_col] for _col in self._name_dict] - _label_list = [_name for _name in self._name_dict.values()] + _label_list = list(self._name_dict.values()) _fig = create_distplot(_data_list, _label_list, show_rug=False, **self._graph_kwargs) return _fig["data"] diff --git a/qlib/data/cache.py b/qlib/data/cache.py index 0174dc63f..2d0b8a7cd 100644 --- a/qlib/data/cache.py +++ b/qlib/data/cache.py @@ -1045,9 +1045,6 @@ class SimpleDatasetCache(DatasetCache): class DatasetURICache(DatasetCache): """Prepared cache mechanism for server.""" - def __init__(self, provider): - super(DatasetURICache, self).__init__(provider) - def _uri(self, instruments, fields, start_time, end_time, freq, disk_cache=1, **kwargs): return hash_args(*self.normalize_uri_args(instruments, fields, freq), disk_cache) diff --git a/qlib/data/data.py b/qlib/data/data.py index 762467da3..000bd1196 100644 --- a/qlib/data/data.py +++ b/qlib/data/data.py @@ -654,9 +654,6 @@ class LocalExpressionProvider(ExpressionProvider): Provide expression data from local data source. """ - def __init__(self): - super().__init__() - def expression(self, instrument, field, start_time=None, end_time=None, freq="day"): expression = self.get_expression_instance(field) start_time = pd.Timestamp(start_time) diff --git a/qlib/data/dataset/__init__.py b/qlib/data/dataset/__init__.py index 690436ba9..0cdb598f2 100644 --- a/qlib/data/dataset/__init__.py +++ b/qlib/data/dataset/__init__.py @@ -76,18 +76,7 @@ class DatasetH(Dataset): - The processing is related to data split. """ - def __init__(self, handler: Union[Dict, DataHandler], segments: Dict): - """ - Parameters - ---------- - handler : Union[dict, DataHandler] - handler will be passed into setup_data. - segments : dict - handler will be passed into setup_data. - """ - super().__init__(handler, segments) - - def init(self, handler_kwargs: Optional[Dict] = None, segment_kwargs: Optional[Dict] = None): + def init(self, handler_kwargs: dict = None, segment_kwargs: dict = None): """ Initialize the DatasetH diff --git a/qlib/utils/__init__.py b/qlib/utils/__init__.py index 68d7d8f3f..1ee6f07a1 100644 --- a/qlib/utils/__init__.py +++ b/qlib/utils/__init__.py @@ -212,7 +212,7 @@ def get_cls_kwargs(config: Union[dict, str], module) -> (type, dict): def init_instance_by_config( - config: Union[str, dict, object], module=None, accept_types: Union[type, Tuple[type]] = tuple([]), **kwargs + config: Union[str, dict, object], module=None, accept_types: Union[type, Tuple[type]] = (), **kwargs ) -> object: """ get initialized instance with config