Skip to content

Commit 7f58716

Browse files
committed
move a few warnings to use python's system
1 parent b78a4cd commit 7f58716

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
- Linting fixups.
1010

1111
### [Mods Base v1.10](https://github.com/bl-sdk/mods_base/blob/master/Readme.md#v19)
12-
> - Linting fixups.
12+
> - Moved a few warnings to go through Python's system, so they get attributed to the right place.
1313
1414
### Save Options v1.2
1515
- Fixed issue where loading a character with no save option data inherited option values from
1616
previous character.
17+
- Moved a few warnings to go through Python's system, so they get attributed to the right place.
1718

1819
### UI Utils v1.3
1920
- Linting fixes.

src/save_options/registration.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import contextlib
22
import inspect
3+
import warnings
34
from collections.abc import Callable, Sequence
5+
from pathlib import Path
46
from typing import Any
57

6-
from unrealsdk import logging
7-
88
from mods_base import BaseOption, GroupedOption, Mod, NestedOption
99
from save_options.options import SaveOption
1010

@@ -20,6 +20,8 @@
2020

2121
registered_mods: dict[str, Mod] = {}
2222

23+
_WARNING_SKIPS: tuple[str] = (str(Path(__file__).parent),)
24+
2325

2426
def _treat_as_save_option(obj: Any) -> bool:
2527
"""
@@ -46,9 +48,11 @@ def _treat_as_save_option(obj: Any) -> bool:
4648
if all(_treat_as_save_option(child) for child in obj.children):
4749
return True
4850
if any(_treat_as_save_option(child) for child in obj.children):
49-
logging.dev_warning(
51+
warnings.warn(
5052
f"Option {obj.identifier} has both regular BaseOption and SaveOption"
5153
f" defined as children. SaveOption instances will be ignored.",
54+
stacklevel=2,
55+
skip_file_prefixes=_WARNING_SKIPS,
5256
)
5357
return False
5458

@@ -107,13 +111,19 @@ def register_save_options( # noqa: C901, D417
107111
if _treat_as_save_option(option):
108112
new_save_options.append(option)
109113
else:
110-
logging.dev_warning(f"Cannot register {option} as a SaveOption")
114+
warnings.warn(
115+
f"Cannot register {option} as a SaveOption",
116+
stacklevel=2,
117+
skip_file_prefixes=_WARNING_SKIPS,
118+
)
111119
else:
112120
for _, value in inspect.getmembers(module):
113121
if isinstance(value, GroupedOption | NestedOption):
114-
logging.dev_warning(
115-
f"{module.__name__}: {type(value).__name__} instances must be explicitly"
116-
f" specified in the options list!",
122+
warnings.warn(
123+
f"{type(value).__name__} instances must be explicitly specified in the options"
124+
f" list!",
125+
stacklevel=2,
126+
skip_file_prefixes=_WARNING_SKIPS,
117127
)
118128
elif _treat_as_save_option(value):
119129
new_save_options.append(value)

0 commit comments

Comments
 (0)