Skip to content

Commit a2d45d3

Browse files
committed
move a few warnings to use python's system
the ones in `options.py` were just plain overlooked the other two have non-trivial stack levels, which skip file prefixes solves
1 parent ec78c07 commit a2d45d3

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ game specific things:
2020
# Changelog
2121

2222
### v1.10
23-
- Linting fixups.
23+
- Moved a few warnings to go through Python's system, so they get attributed to the right place.
2424

2525
### v1.9
2626
- Added a new `CoopSupport.HostOnly` value.

mod.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import inspect
44
import sys
5+
import warnings
56
from dataclasses import dataclass, field
67
from enum import Enum, Flag, auto
78
from functools import cache
@@ -19,6 +20,8 @@
1920
if TYPE_CHECKING:
2021
from collections.abc import Callable, Iterator, Sequence
2122

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

2326
class Game(Flag):
2427
"""A flags enum of the supported games."""
@@ -197,9 +200,11 @@ def __post_init__(self) -> None: # noqa: C901 - difficult to split up
197200
case KeybindType() if find_keybinds:
198201
new_keybinds.append(value)
199202
case GroupedOption() | NestedOption() if find_options:
200-
logging.dev_warning(
203+
warnings.warn(
201204
f"{self.name}: {type(value).__name__} instances must be explicitly"
202205
f" specified in the options list!",
206+
stacklevel=2,
207+
skip_file_prefixes=_WARNING_SKIPS,
203208
)
204209
case BaseOption() if find_options:
205210
new_options.append(value)

mod_factory.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import inspect
44
import operator
55
import tomllib
6+
import warnings
67
from collections.abc import Callable, Sequence
78
from pathlib import Path
89
from types import ModuleType
910
from typing import Any, TypedDict
1011

11-
from unrealsdk import logging
12-
1312
from .command import AbstractCommand
1413
from .dot_sdkmod import open_in_mod_dir
1514
from .hook import HookType
@@ -19,6 +18,8 @@
1918
from .options import BaseOption, GroupedOption, NestedOption
2019
from .settings import SETTINGS_DIR
2120

21+
_WARNING_SKIPS: tuple[str] = (str(Path(__file__).parent),)
22+
2223

2324
def build_mod[T: Mod = Mod](
2425
*,
@@ -321,9 +322,11 @@ def update_fields_with_module_search( # noqa: C901 - difficult to split up
321322
new_keybinds.append(value)
322323

323324
case GroupedOption() | NestedOption() if find_options:
324-
logging.dev_warning(
325+
warnings.warn(
325326
f"{module.__name__}: {type(value).__name__} instances must be explicitly"
326327
f" specified in the options list!",
328+
stacklevel=2,
329+
skip_file_prefixes=_WARNING_SKIPS,
327330
)
328331
case BaseOption() if find_options:
329332
new_options.append(value)

options.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from abc import ABC, abstractmethod
23
from collections.abc import Callable, Mapping, Sequence
34
from dataclasses import KW_ONLY, dataclass, field
@@ -136,9 +137,10 @@ def __call__(self, on_change: Callable[[Self, J], None]) -> Self:
136137
This option instance.
137138
"""
138139
if self.on_change is not None:
139-
logging.dev_warning(
140+
warnings.warn(
140141
f"{self.__class__.__qualname__}.__call__ was called on an option which already has"
141142
f" a on change callback.",
143+
stacklevel=2,
142144
)
143145

144146
self.on_change = on_change
@@ -385,9 +387,10 @@ def __call__(self, on_press: Callable[[Self], None]) -> Self:
385387
This option instance.
386388
"""
387389
if self.on_press is not None:
388-
logging.dev_warning(
390+
warnings.warn(
389391
f"{self.__class__.__qualname__}.__call__ was called on an option which already has"
390392
f" a on press callback.",
393+
stacklevel=2,
391394
)
392395

393396
self.on_press = on_press

0 commit comments

Comments
 (0)