aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Steele Farnsworth <[email protected]>2025-01-19 12:16:14 -0500
committerGravatar Steele Farnsworth <[email protected]>2025-01-19 12:16:14 -0500
commit3ea3a27fb0792e73744ce315e2a512ead09e3112 (patch)
treef9ddbaee712954bf43044937539a8e99206d7224
parentMigrate to py3.12 generic syntax (removes TypeVar). (diff)
Migrate to py3.12 typing syntax.
-rw-r--r--bot/exts/filtering/_settings.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/bot/exts/filtering/_settings.py b/bot/exts/filtering/_settings.py
index 7005dd2d1..6760a3f01 100644
--- a/bot/exts/filtering/_settings.py
+++ b/bot/exts/filtering/_settings.py
@@ -5,7 +5,7 @@ import traceback
from abc import abstractmethod
from copy import copy
from functools import reduce
-from typing import Any, NamedTuple, Self, TypeVar
+from typing import Any, NamedTuple, Self
from bot.exts.filtering._filter_context import FilterContext
from bot.exts.filtering._settings_types import settings_types
@@ -13,13 +13,9 @@ from bot.exts.filtering._settings_types.settings_entry import ActionEntry, Setti
from bot.exts.filtering._utils import FieldRequiring
from bot.log import get_logger
-TSettings = TypeVar("TSettings", bound="Settings")
-
log = get_logger(__name__)
-_already_warned: set[str] = set()
-
-T = TypeVar("T", bound=SettingsEntry)
+_already_warned = set[str]()
def create_settings(
@@ -55,7 +51,7 @@ def create_settings(
)
-class Settings(FieldRequiring, dict[str, T]):
+class Settings[T: SettingsEntry](FieldRequiring, dict[str, T]):
"""
A collection of settings.
@@ -69,7 +65,7 @@ class Settings(FieldRequiring, dict[str, T]):
entry_type: type[T]
- _already_warned: set[str] = set()
+ _already_warned = set[str]()
@abstractmethod # ABCs have to have at least once abstract method to actually count as such.
def __init__(self, settings_data: dict, *, defaults: Settings | None = None, keep_empty: bool = False):
@@ -104,7 +100,7 @@ class Settings(FieldRequiring, dict[str, T]):
"""Return a dictionary of overrides across all entries."""
return reduce(operator.or_, (entry.overrides for entry in self.values() if entry), {})
- def copy(self: TSettings) -> TSettings:
+ def copy(self: Self) -> Self:
"""Create a shallow copy of the object."""
return copy(self)