mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-26 11:12:50 +00:00
fix: add default to getattr
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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}'")
|
||||
|
||||
Reference in New Issue
Block a user