From 06bc29540477cc5abb76816c5c0a491b0d111d00 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 21 Sep 2023 10:21:14 +0100 Subject: [PATCH] Ignore pydantic depracted warning when searching for custom attr --- bot/exts/filtering/_utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bot/exts/filtering/_utils.py b/bot/exts/filtering/_utils.py index 944cf38370..5fe3bd3c9b 100644 --- a/bot/exts/filtering/_utils.py +++ b/bot/exts/filtering/_utils.py @@ -5,6 +5,7 @@ import inspect import pkgutil import types +import warnings from abc import ABC, abstractmethod from collections import defaultdict from collections.abc import Callable, Iterable @@ -15,6 +16,7 @@ import discord import regex from discord.ext.commands import Command +from pydantic import PydanticDeprecatedSince20 from pydantic_core import core_schema import bot @@ -181,11 +183,16 @@ def inherited(attr: str) -> bool: # If a new attribute with the value MUST_SET_UNIQUE was defined in an abstract class, record it. if inspect.isabstract(cls): - for attribute in dir(cls): - if getattr(cls, attribute, None) is FieldRequiring.MUST_SET_UNIQUE: - if not inherited(attribute): - # A new attribute with the value MUST_SET_UNIQUE. - FieldRequiring.__unique_attributes[cls][attribute] = set() + with warnings.catch_warnings(): + # The code below will raise a warning about the use the __fields__ attr on a pydantic model + # This will continue to be warned about until removed in pydantic 3.0 + # This warning is a false-positive as only the custom MUST_SET_UNIQUE attr is used here + warnings.simplefilter("ignore", category=PydanticDeprecatedSince20) + for attribute in dir(cls): + if getattr(cls, attribute, None) is FieldRequiring.MUST_SET_UNIQUE: + if not inherited(attribute): + # A new attribute with the value MUST_SET_UNIQUE. + FieldRequiring.__unique_attributes[cls][attribute] = set() return for attribute in dir(cls):