Skip to content

Commit 8a53174

Browse files
committed
More UNTESTED type hints
1 parent 4e23734 commit 8a53174

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

scratchattach/site/_base.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
from abc import ABC, abstractmethod
2+
23
import requests
3-
from threading import Thread
4+
# from threading import Thread
45
from ..utils import exceptions, commons
56

7+
68
class BaseSiteComponent(ABC):
9+
@abstractmethod
10+
def __init__(self):
11+
self._session = None
12+
self._cookies = None
13+
self._headers = None
14+
self.update_API = None
715

816
def update(self):
917
"""
1018
Updates the attributes of the object by performing an API response. Returns True if the update was successful.
1119
"""
1220
response = self.update_function(
1321
self.update_API,
14-
headers = self._headers,
15-
cookies = self._cookies, timeout=10
22+
headers=self._headers,
23+
cookies=self._cookies, timeout=10
1624
)
1725
# Check for 429 error:
1826
if "429" in str(response):
@@ -44,3 +52,7 @@ def _make_linked_object(self, identificator_id, identificator, Class, NotFoundEx
4452
"""
4553
return commons._get_object(identificator_id, identificator, Class, NotFoundException, self._session)
4654

55+
update_function = requests.get
56+
"""
57+
Internal function run on update. Function is a method of the 'requests' module/class
58+
"""

scratchattach/site/forum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class ForumTopic(BaseSiteComponent):
3232
3333
:.update(): Updates the attributes
3434
'''
35-
def __init__(self, **entries):
3635

36+
def __init__(self, **entries):
3737
# Info on how the .update method has to fetch the data:
3838
self.update_function = requests.get
3939
self.update_API = f"https://scratch.mit.edu/discuss/feeds/topic/{entries['id']}/"

scratchattach/utils/commons.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"""v2 ready: Common functions used by various internal modules"""
22
from types import FunctionType
3-
from typing import Final, Any
3+
from typing import Final, Any, TYPE_CHECKING
44

55
from . import exceptions
66
from .requests import Requests as requests
77

8+
if TYPE_CHECKING:
9+
# Having to do this is quite inelegant, but this is commons.py, so this is done to avoid cyclic imports
10+
from ..site._base import BaseSiteComponent
11+
812
headers: Final = {
913
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
1014
"(KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36",
@@ -60,7 +64,7 @@
6064
}
6165

6266

63-
def api_iterative_data(fetch_func: 'FunctionType', limit: int, offset: int, max_req_limit: int = 40,
67+
def api_iterative_data(fetch_func: FunctionType, limit: int, offset: int, max_req_limit: int = 40,
6468
unpack: bool = True):
6569
"""
6670
Iteratively gets data by calling fetch_func with a moving offset and a limit.
@@ -123,7 +127,7 @@ def fetch(off: int, lim: int):
123127
return api_data
124128

125129

126-
def _get_object(identificator_name, identificator, Class, NotFoundException, session=None):
130+
def _get_object(identificator_name, identificator, Class, NotFoundException, session=None) -> 'BaseSiteComponent':
127131
# Internal function: Generalization of the process ran by get_user, get_studio etc.
128132
# Builds an object of class that is inheriting from BaseSiteComponent
129133
# # Class must inherit from BaseSiteComponent

0 commit comments

Comments
 (0)