From 3510f390b18a7ef7480216c74f7e787343934f63 Mon Sep 17 00:00:00 2001 From: Lara Maia Date: Fri, 30 Aug 2024 16:04:51 -0300 Subject: [PATCH] QA Fixes --- src/stlib/client.py | 4 ++-- src/stlib/community.py | 12 ++++++------ src/stlib/login.py | 5 +---- src/stlib/plugins.py | 4 ++-- src/stlib/universe.py | 4 ++-- src/stlib/utils.py | 3 +-- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/stlib/client.py b/src/stlib/client.py index fcd26cc..6124bbb 100755 --- a/src/stlib/client.py +++ b/src/stlib/client.py @@ -41,11 +41,11 @@ try: from stlib import steamworks # type: ignore -except ImportError: +except ImportError as exception: raise NoSteamWorksError( 'stlib has been built without SteamWorks support. ' 'Client interface is unavailable' - ) + ) from exception log = logging.getLogger(__name__) diff --git a/src/stlib/community.py b/src/stlib/community.py index bcbd451..8bce590 100644 --- a/src/stlib/community.py +++ b/src/stlib/community.py @@ -258,7 +258,7 @@ async def get_inventory( :return: List of `Item` """ params = {'l': 'english', 'count': count} - json_data = {} + json_data: Dict[str, Any] = {} while True: json_data |= await self.request_json( @@ -560,7 +560,7 @@ async def get_my_orders(self) -> Tuple[List[Order], List[Order]]: :return: sell orders (`Order`) and buy orders (`Order`) """ params = {"start": 0, "count": 100, "norender": 1, "l": "english"} - json_data = {} + json_data: Dict[str, Any] = {} while True: json_data |= await self.request_json( @@ -640,8 +640,8 @@ async def get_item_histogram(self, appid: int, hash_name: str) -> Histogram: start = item_activity_func.index("LoadOrderSpread") + 17 end = item_activity_func[start:].index(" );") + start item_nameid = item_activity_func[start:end] - except ValueError: - raise MarketError("Unable to load market orders") + except ValueError as exception: + raise MarketError("Unable to load market orders") from exception wallet_vars = self.get_vars_from_js(scripts[-2]) @@ -664,8 +664,8 @@ async def get_item_histogram(self, appid: int, hash_name: str) -> Histogram: f"{self.community_url}/market/itemordershistogram", params=params ) - sell_order_table = [] - buy_order_table = [] + sell_order_table: List[PriceInfo] = [] + buy_order_table: List[PriceInfo] = [] if 'sell_order_table' in json_data and json_data['sell_order_table']: sell_order_table.extend( diff --git a/src/stlib/login.py b/src/stlib/login.py index 709d0e4..141ac59 100644 --- a/src/stlib/login.py +++ b/src/stlib/login.py @@ -378,7 +378,4 @@ async def is_limited(self) -> bool: html = await self.request_html('https://steamcommunity.com/dev/apikey') main = html.find('div', id='mainContents') - if 'Access Denied' in main.find('h2').text: - return True - - return False + return 'Access Denied' in main.find('h2').text diff --git a/src/stlib/plugins.py b/src/stlib/plugins.py index 7348444..6027019 100644 --- a/src/stlib/plugins.py +++ b/src/stlib/plugins.py @@ -91,7 +91,7 @@ def __init__(self, custom_search_paths: Tuple[str, ...] = ()) -> None: try: plugin_spec.loader.exec_module(module_) # type: ignore except ImportError as exception: - raise PluginLoaderError(exception) + raise PluginLoaderError(exception) from exception log.debug("Plugin %s loaded.", module_name) self._plugins[module_.__name__] = module_ @@ -147,7 +147,7 @@ def get_available_plugins() -> List[str]: Return a list of available plugins :return: list of available plugins """ - return list(manager.plugins.keys()) + return list(manager.plugins.keys()) # noqa @_plugin_manager diff --git a/src/stlib/universe.py b/src/stlib/universe.py index 5de4fb5..0805b82 100755 --- a/src/stlib/universe.py +++ b/src/stlib/universe.py @@ -110,7 +110,7 @@ def __add__(self, value: int | float) -> 'SteamPrice': def __sub__(self, value: int | float) -> 'SteamPrice': return SteamPrice(round(self._price - value, 2)) - def __lt__(self, other: Self) -> bool: + def __lt__(self, other: object) -> bool: if isinstance(other, int): return round(self._price * 100) < other elif isinstance(other, float): @@ -120,7 +120,7 @@ def __lt__(self, other: Self) -> bool: else: raise NotImplementedError(f"Comparation with {type(other)} not implemented") - def __eq__(self, other: Self) -> bool: + def __eq__(self, other: object) -> bool: if isinstance(other, int): return round(self._price * 100) == other elif isinstance(other, float): diff --git a/src/stlib/utils.py b/src/stlib/utils.py index 1542479..0857485 100644 --- a/src/stlib/utils.py +++ b/src/stlib/utils.py @@ -20,15 +20,14 @@ """ import asyncio +import atexit import contextlib import http.cookies import json -import locale import logging from typing import Dict, Any, NamedTuple, Self import aiohttp -import atexit from bs4 import BeautifulSoup log = logging.getLogger(__name__)