fix: add default to getattr

This commit is contained in:
montezdesousa
2024-02-12 12:00:34 +00:00
parent d6fc032081
commit cbde4bc064
2 changed files with 6 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
"""The OpenBB Standardized QueryParams Model that holds the query input parameters."""
from typing import Dict
from typing import Dict, Optional
from pydantic import BaseModel, ConfigDict, model_validator
@@ -24,8 +24,8 @@ class QueryParams(BaseModel):
def _apply_validators(cls, values):
for v, fields in cls.__validator_dict__.items():
for f in fields:
func: validators.V
if f in values and (func := getattr(validators, v)):
func: Optional[validators.V]
if f in values and (func := getattr(validators, v, None)):
values[f] = func(f, values[f])
return values

View File

@@ -1,11 +1,11 @@
"""Field validators"""
from typing import Any, Callable, Optional, TypeVar
from typing import Any, Callable, NewType, Optional
V = TypeVar("V", Callable[[str, Any], Any])
V = NewType("V", Callable[[str, Any], Any])
def check_single(field: str, value: Optional[str]) -> Optional[str]:
def check_singles(field: str, value: Optional[str]) -> Optional[str]:
"""Check that string is a single value."""
if value and ("," in value or ";" in value):
raise ValueError(f"multiple values not allowed for field '{field}'")