From 09fab962d426a921791173198f823e9a1dd29fc3 Mon Sep 17 00:00:00 2001 From: drew2a Date: Mon, 2 Oct 2023 12:28:40 +0200 Subject: [PATCH] Fix linter and pytest issues --- .../database/db/layers/health_data_access_level.py | 9 ++++++--- .../database/db/layers/knowledge_data_access_layer.py | 9 ++++++--- .../core/components/database/db/tribler_database.py | 4 ++-- .../knowledge/rules/knowledge_rules_processor.py | 3 ++- src/tribler/gui/tests/test_gui.py | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/tribler/core/components/database/db/layers/health_data_access_level.py b/src/tribler/core/components/database/db/layers/health_data_access_level.py index 9cd3d2f5432..b4dc8367473 100644 --- a/src/tribler/core/components/database/db/layers/health_data_access_level.py +++ b/src/tribler/core/components/database/db/layers/health_data_access_level.py @@ -2,19 +2,22 @@ import logging from pony import orm -from tribler.core.components.database.db.layers.knowledge_data_access_layer import KnowledgeDataAccessLayer +from tribler.core.components.database.db.layers.knowledge_data_access_layer import KnowledgeDataAccessLayer from tribler.core.components.torrent_checker.torrent_checker.dataclasses import HealthInfo from tribler.core.upgrade.tags_to_knowledge.previous_dbs.knowledge_db import ResourceType from tribler.core.utilities.pony_utils import get_or_create +# pylint: disable=redefined-outer-name + + class HealthDataAccessLayer: def __init__(self, knowledge_layer: KnowledgeDataAccessLayer): self.logger = logging.getLogger(self.__class__.__name__) self.instance = knowledge_layer.instance self.Resource = knowledge_layer.Resource - self.HealthInfo, = self.define_binding(self.instance) + self.HealthInfo = self.define_binding(self.instance) @staticmethod def define_binding(db): @@ -28,7 +31,7 @@ class HealthInfo(db.Entity): source = orm.Required(int, default=0) # Source enum last_check = orm.Required(datetime.datetime, default=datetime.datetime.utcnow) - return HealthInfo, + return HealthInfo def add_torrent_health(self, torrent_health: HealthInfo): torrent = get_or_create( diff --git a/src/tribler/core/components/database/db/layers/knowledge_data_access_layer.py b/src/tribler/core/components/database/db/layers/knowledge_data_access_layer.py index ecd90cea5cd..2d60674fb84 100644 --- a/src/tribler/core/components/database/db/layers/knowledge_data_access_layer.py +++ b/src/tribler/core/components/database/db/layers/knowledge_data_access_layer.py @@ -20,6 +20,9 @@ HIDE_THRESHOLD = -2 # how many operation needed for hiding a knowledge graph statement in the UI +# pylint: disable=redefined-outer-name + + class Operation(IntEnum): """ Available types of statement operations.""" ADD = 1 # +1 operation @@ -178,7 +181,6 @@ def _get_statements(source_type: Optional[ResourceType], source_name: Optional[s return Peer, Statement, Resource, StatementOp, _get_statements - def add_operation(self, operation: StatementOperation, signature: bytes, is_local_peer: bool = False, is_auto_generated: bool = False, counter_increment: int = 1) -> bool: """ Add the operation that will be applied to a statement. @@ -361,9 +363,10 @@ def get_suggestions(self, subject_type: Optional[ResourceType] = None, subject: ) return suggestions - def get_subjects_intersection(self, objects: Set[str], predicate: Optional[ResourceType], + def get_subjects_intersection(self, objects: Set[str], + predicate: Optional[ResourceType], # pylint: disable=unused-argument subjects_type: Optional[ResourceType] = ResourceType.TORRENT, - case_sensitive: bool = True) -> Set[str]: # pylint: disable=unused-argument + case_sensitive: bool = True) -> Set[str]: if not objects: return set() diff --git a/src/tribler/core/components/database/db/tribler_database.py b/src/tribler/core/components/database/db/tribler_database.py index 559f99ec23e..546c0823772 100644 --- a/src/tribler/core/components/database/db/tribler_database.py +++ b/src/tribler/core/components/database/db/tribler_database.py @@ -15,7 +15,7 @@ def __init__(self, filename: Optional[str] = None, *, create_tables: bool = True self.knowledge = KnowledgeDataAccessLayer(self.instance) self.health = HealthDataAccessLayer(self.knowledge) - self.Misc, = self.define_binding(self.instance) + self.Misc = self.define_binding(self.instance) self.Peer = self.knowledge.Peer self.Statement = self.knowledge.Statement @@ -37,7 +37,7 @@ class Misc(db.Entity): # pylint: disable=unused-variable name = orm.PrimaryKey(str) value = orm.Optional(str) - return Misc, + return Misc def get_misc(self, key: str, default: Optional[str] = None) -> Optional[str]: data = self.Misc.get(name=key) diff --git a/src/tribler/core/components/knowledge/rules/knowledge_rules_processor.py b/src/tribler/core/components/knowledge/rules/knowledge_rules_processor.py index 128076ee962..ddac871fc0d 100644 --- a/src/tribler/core/components/knowledge/rules/knowledge_rules_processor.py +++ b/src/tribler/core/components/knowledge/rules/knowledge_rules_processor.py @@ -222,7 +222,8 @@ async def process_torrent_title(self, infohash: Optional[bytes] = None, title: O def save_statements(self, subject_type: ResourceType, subject: str, predicate: ResourceType, objects: Set[str]): self.logger.debug(f'Save: {len(objects)} objects for "{subject}" with predicate={predicate}') for obj in objects: - self.db.knowledge.add_auto_generated_operation(subject_type=subject_type, subject=subject, predicate=predicate, obj=obj) + self.db.knowledge.add_auto_generated_operation(subject_type=subject_type, subject=subject, + predicate=predicate, obj=obj) @db_session def get_last_processed_torrent_id(self) -> int: diff --git a/src/tribler/gui/tests/test_gui.py b/src/tribler/gui/tests/test_gui.py index 9efbb346e52..6cc9fa2f9e2 100644 --- a/src/tribler/gui/tests/test_gui.py +++ b/src/tribler/gui/tests/test_gui.py @@ -10,7 +10,7 @@ from PyQt5.QtWidgets import QListWidget, QTableView, QTextEdit, QTreeWidget, QTreeWidgetItem import tribler.gui -from tribler.core.components.database.db.tribler_database import ResourceType +from tribler.core.components.database.db.layers.knowledge_data_access_layer import ResourceType from tribler.core.components.knowledge.knowledge_constants import MIN_RESOURCE_LENGTH from tribler.core.components.reporter.reported_error import ReportedError from tribler.core.sentry_reporter.sentry_reporter import SentryReporter