Skip to content

Commit

Permalink
Ignore pydantic depracted warning when searching for custom attr
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Nov 25, 2023
1 parent 74f2381 commit 06bc295
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions bot/exts/filtering/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 06bc295

Please sign in to comment.