Skip to content

Commit 65c3d9f

Browse files
committed
feat: warnings.warn instead of print
this does not cover all cases, but it covers some
1 parent 1a5f414 commit 65c3d9f

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

scratchattach/site/backpack_asset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import time
55
import logging
6+
import warnings
67

78
from ._base import BaseSiteComponent
89
from scratchattach.utils import exceptions
@@ -39,7 +40,7 @@ def __init__(self, **entries):
3940
self.__dict__.update(entries)
4041

4142
def update(self):
42-
print("Warning: BackpackAsset objects can't be updated")
43+
warnings.warn("Warning: BackpackAsset objects can't be updated")
4344
return False # Objects of this type cannot be updated
4445

4546

scratchattach/site/comment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Comment class"""
22
from __future__ import annotations
33

4+
import warnings
45
from typing import Union, Optional, Any
56
from typing_extensions import assert_never # importing from typing caused me errors
67
from enum import Enum, auto
@@ -48,7 +49,7 @@ def __init__(self, **entries):
4849
self.source = "Unknown"
4950

5051
def update(self):
51-
print("Warning: Comment objects can't be updated")
52+
warnings.warn("Warning: Comment objects can't be updated")
5253
return False # Objects of this type cannot be updated
5354

5455
def _update_from_dict(self, data):

scratchattach/site/forum.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""ForumTopic and ForumPost classes"""
22
from __future__ import annotations
33

4+
import warnings
45
from dataclasses import dataclass, field
56
from typing import Optional, Any
67
from urllib.parse import urlparse, parse_qs
@@ -114,7 +115,7 @@ def posts(self, *, page=1, order="oldest") -> list[ForumPost]:
114115
list<scratchattach.forum.ForumPost>: A list containing the posts from the specified page of the forum topic
115116
"""
116117
if order != "oldest":
117-
print("Warning: All post orders except for 'oldest' are deprecated and no longer work") # For backwards compatibility
118+
warnings.warn("Warning: All post orders except for 'oldest' are deprecated and no longer work") # For backwards compatibility
118119

119120
posts = []
120121

@@ -143,7 +144,7 @@ def posts(self, *, page=1, order="oldest") -> list[ForumPost]:
143144
link = breadcrumb_ul.find_all('a')[1] # Get the right anchor tag
144145
topic_category = link.text.strip() # Extract and strip text content
145146
except Exception as e:
146-
print(f"Warning: Couldn't scrape topic category for topic {self.id} - {e}")
147+
warnings.warn(f"Warning: Couldn't scrape topic category for topic {self.id} - {e}")
147148
topic_category = ""
148149

149150
# get corresponding posts:

0 commit comments

Comments
 (0)