black fixes
This commit is contained in:
parent
a5d197c2fb
commit
faebd22185
@ -65,7 +65,9 @@ class Base(pydantic.BaseModel):
|
|||||||
"""
|
"""
|
||||||
from reflex.utils.serializers import serialize
|
from reflex.utils.serializers import serialize
|
||||||
|
|
||||||
return self.__pydantic_serializer__.to_json(value=self, fallback=serialize).decode()
|
return self.__pydantic_serializer__.to_json(
|
||||||
|
value=self, fallback=serialize
|
||||||
|
).decode()
|
||||||
|
|
||||||
def set(self, **kwargs):
|
def set(self, **kwargs):
|
||||||
"""Set multiple fields and return the object.
|
"""Set multiple fields and return the object.
|
||||||
@ -89,7 +91,6 @@ class Base(pydantic.BaseModel):
|
|||||||
"""
|
"""
|
||||||
return cls.model_fields
|
return cls.model_fields
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_field(cls, var: Any, default_value: Any):
|
def add_field(cls, var: Any, default_value: Any):
|
||||||
"""Add a pydantic field after class definition.
|
"""Add a pydantic field after class definition.
|
||||||
@ -104,7 +105,6 @@ class Base(pydantic.BaseModel):
|
|||||||
cls.model_fields.update({var._var_name: field_info})
|
cls.model_fields.update({var._var_name: field_info})
|
||||||
cls.model_rebuild(force=True)
|
cls.model_rebuild(force=True)
|
||||||
|
|
||||||
|
|
||||||
def get_value(self, key: str) -> Any:
|
def get_value(self, key: str) -> Any:
|
||||||
"""Get the value of a field.
|
"""Get the value of a field.
|
||||||
|
|
||||||
|
@ -159,6 +159,7 @@ SPECIAL_METHODS = {
|
|||||||
"model_post_init", # never treat this as an event handler
|
"model_post_init", # never treat this as an event handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _substate_key(
|
def _substate_key(
|
||||||
token: str,
|
token: str,
|
||||||
state_cls_or_name: BaseState | Type[BaseState] | str | list[str],
|
state_cls_or_name: BaseState | Type[BaseState] | str | list[str],
|
||||||
@ -435,9 +436,9 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
|||||||
|
|
||||||
# Set the base and computed vars.
|
# Set the base and computed vars.
|
||||||
cls.base_vars = {
|
cls.base_vars = {
|
||||||
field_name: BaseVar(_var_name=field_name, _var_type=field.annotation)._var_set_state(
|
field_name: BaseVar(
|
||||||
cls
|
_var_name=field_name, _var_type=field.annotation
|
||||||
)
|
)._var_set_state(cls)
|
||||||
for field_name, field in cls.get_fields().items()
|
for field_name, field in cls.get_fields().items()
|
||||||
if field_name not in cls.get_skip_vars()
|
if field_name not in cls.get_skip_vars()
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,11 @@ def get_attribute_access_type(cls: GenericType, name: str) -> GenericType | None
|
|||||||
# pydantic models
|
# pydantic models
|
||||||
field = cls.model_fields[name]
|
field = cls.model_fields[name]
|
||||||
type_ = field.annotation
|
type_ = field.annotation
|
||||||
if not field.is_required() and field.default is None and field.default_factory is None:
|
if (
|
||||||
|
not field.is_required()
|
||||||
|
and field.default is None
|
||||||
|
and field.default_factory is None
|
||||||
|
):
|
||||||
# Ensure frontend uses null coalescing when accessing.
|
# Ensure frontend uses null coalescing when accessing.
|
||||||
type_ = Optional[type_]
|
type_ = Optional[type_]
|
||||||
return type_
|
return type_
|
||||||
|
@ -220,7 +220,9 @@ def _encode_var(value: Var) -> str:
|
|||||||
final_value = str(value)
|
final_value = str(value)
|
||||||
data = value._var_data.dict()
|
data = value._var_data.dict()
|
||||||
data["string_length"] = len(final_value)
|
data["string_length"] = len(final_value)
|
||||||
data_json = value._var_data.__pydantic_serializer__.to_json(value=data, fallback=serialize).decode()
|
data_json = value._var_data.__pydantic_serializer__.to_json(
|
||||||
|
value=data, fallback=serialize
|
||||||
|
).decode()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
f"{constants.REFLEX_VAR_OPENING_TAG}{data_json}{constants.REFLEX_VAR_CLOSING_TAG}"
|
f"{constants.REFLEX_VAR_OPENING_TAG}{data_json}{constants.REFLEX_VAR_CLOSING_TAG}"
|
||||||
@ -243,7 +245,6 @@ def _decode_var(value: str) -> tuple[VarData | None, str]:
|
|||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
|
|
||||||
def json_loads(s):
|
def json_loads(s):
|
||||||
try:
|
try:
|
||||||
return VarData.model_validate(s)
|
return VarData.model_validate(s)
|
||||||
|
Loading…
Reference in New Issue
Block a user