pydantic v2 hacks/fixups
This commit is contained in:
parent
c7eda15470
commit
dc39bcd626
@ -727,7 +727,7 @@ class Component(BaseComponent, ABC):
|
||||
# Get Vars associated with component props.
|
||||
for prop in self.get_props():
|
||||
prop_var = getattr(self, prop)
|
||||
if isinstance(prop_var, Var):
|
||||
if isinstance(prop_var, Var) and prop_var is not UnspecifiedVar:
|
||||
vars.append(prop_var)
|
||||
|
||||
# Style keeps track of its own VarData instance, so embed in a temp Var that is yielded.
|
||||
|
@ -902,7 +902,11 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
||||
for prop_name in self.base_vars:
|
||||
if prop_name == constants.ROUTER:
|
||||
continue # never reset the router data
|
||||
setattr(self, prop_name, copy.deepcopy(fields[prop_name].default))
|
||||
if fields[prop_name].is_required():
|
||||
value = self.base_vars[prop_name].get_default_value()
|
||||
else:
|
||||
value = copy.deepcopy(fields[prop_name].default)
|
||||
setattr(self, prop_name, copy.deepcopy(value))
|
||||
|
||||
# Recursively reset the substates.
|
||||
for substate in self.substates.values():
|
||||
@ -916,8 +920,8 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
||||
for prop_name in self.base_vars:
|
||||
field = fields[prop_name]
|
||||
if isinstance(field.default, ClientStorageBase) or (
|
||||
isinstance(field.type_, type)
|
||||
and issubclass(field.type_, ClientStorageBase)
|
||||
isinstance(field.annotation, type)
|
||||
and issubclass(field.annotation, ClientStorageBase)
|
||||
):
|
||||
setattr(self, prop_name, copy.deepcopy(field.default))
|
||||
|
||||
|
@ -632,6 +632,8 @@ class Var:
|
||||
f"wrongly."
|
||||
)
|
||||
|
||||
if name.startswith("_var"):
|
||||
print(name)
|
||||
raise AttributeError(
|
||||
f"The State var has no attribute '{name}' or may have been annotated wrongly.",
|
||||
)
|
||||
@ -1538,10 +1540,6 @@ class Var:
|
||||
serializers.serializer(_encode_var)
|
||||
|
||||
|
||||
# Marker for a Var that was not passed
|
||||
UnspecifiedVar = Var()
|
||||
|
||||
|
||||
@dataclasses.dataclass(
|
||||
eq=False,
|
||||
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
||||
@ -1664,6 +1662,10 @@ class BaseVar(Var):
|
||||
return setter
|
||||
|
||||
|
||||
# Marker for a Var that was not passed
|
||||
UnspecifiedVar = BaseVar(_var_name="<UNSPECIFIED>")
|
||||
|
||||
|
||||
@dataclasses.dataclass(init=False, eq=False)
|
||||
class ComputedVar(Var, property):
|
||||
"""A field with computed getters."""
|
||||
|
@ -339,8 +339,8 @@ def test_node_install_windows(tmp_path, mocker):
|
||||
mocker.patch("reflex.utils.processes.stream_logs")
|
||||
|
||||
class Resp(Base):
|
||||
status_code = 200
|
||||
text = "test"
|
||||
status_code: int = 200
|
||||
text: str = "test"
|
||||
|
||||
mocker.patch("httpx.stream", return_value=Resp())
|
||||
download = mocker.patch("reflex.utils.prerequisites.download_and_extract_fnm_zip")
|
||||
@ -381,8 +381,8 @@ def test_node_install_unix(tmp_path, mocker, machine, system):
|
||||
mocker.patch("reflex.utils.prerequisites.platform.system", return_value=system)
|
||||
|
||||
class Resp(Base):
|
||||
status_code = 200
|
||||
text = "test"
|
||||
status_code: int = 200
|
||||
text: str = "test"
|
||||
|
||||
mocker.patch("httpx.stream", return_value=Resp())
|
||||
download = mocker.patch("reflex.utils.prerequisites.download_and_extract_fnm_zip")
|
||||
|
Loading…
Reference in New Issue
Block a user