Use Any with find() to avoid type warnings

This commit is contained in:
Andrew Brookins 2021-09-29 21:15:26 -07:00
parent 54f00b5774
commit 9a47d1046d

View file

@ -1,10 +1,9 @@
import abc import abc
import dataclasses import dataclasses
import decimal import decimal
import inspect
import operator import operator
import re import re
from copy import deepcopy, copy from copy import deepcopy
from enum import Enum from enum import Enum
from functools import reduce from functools import reduce
from typing import ( from typing import (
@ -32,7 +31,7 @@ from pydantic import BaseModel, validator
from pydantic.fields import FieldInfo as PydanticFieldInfo from pydantic.fields import FieldInfo as PydanticFieldInfo
from pydantic.fields import ModelField, Undefined, UndefinedType from pydantic.fields import ModelField, Undefined, UndefinedType
from pydantic.main import ModelMetaclass from pydantic.main import ModelMetaclass
from pydantic.typing import NoArgAnyCallable from pydantic.typing import NoArgAnyCallable, resolve_annotations
from pydantic.utils import Representation from pydantic.utils import Representation
from .encoders import jsonable_encoder from .encoders import jsonable_encoder
@ -615,16 +614,9 @@ class DefaultMeta:
class ModelMeta(ModelMetaclass): class ModelMeta(ModelMetaclass):
def add_to_class(cls, name, value):
if _has_contribute_to_class(value):
value.contribute_to_class(cls, name)
else:
setattr(cls, name, value)
def __new__(cls, name, bases, attrs, **kwargs): # noqa C901 def __new__(cls, name, bases, attrs, **kwargs): # noqa C901
meta = attrs.pop('Meta', None) meta = attrs.pop('Meta', None)
new_class = super().__new__(cls, name, bases, attrs, **kwargs) new_class = super().__new__(cls, name, bases, attrs, **kwargs)
meta = meta or getattr(new_class, 'Meta', None) meta = meta or getattr(new_class, 'Meta', None)
base_meta = getattr(new_class, '_meta', None) base_meta = getattr(new_class, '_meta', None)
@ -734,7 +726,7 @@ class RedisModel(BaseModel, abc.ABC, metaclass=ModelMeta):
return cls._meta.database return cls._meta.database
@classmethod @classmethod
def find(cls, *expressions: Expression): def find(cls, *expressions: Union[Any, Expression]): # TODO: How to type annotate this?
return FindQuery(expressions=expressions, model=cls) return FindQuery(expressions=expressions, model=cls)
@classmethod @classmethod