replace type_ and outer_type_ with field.annotation

This commit is contained in:
Masen Furer 2023-12-19 15:35:58 -08:00
parent 62d36bfecc
commit c7eda15470
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95
2 changed files with 9 additions and 7 deletions

View File

@ -194,7 +194,7 @@ class Component(BaseComponent, ABC):
ValueError: If a prop value is invalid.
"""
# Set the id and children initially.
children = kwargs.get("children", [])
kwargs.get("children", [])
# kwargs = {
# **{
# prop: Var.create(None) if field.is_required() and types._issubclass(field.annotation, Var) else field.default
@ -551,7 +551,7 @@ class Component(BaseComponent, ABC):
name
for name, field in cls.get_fields().items()
if name in cls.get_props()
and types._issubclass(field.outer_type_, Component)
and types._issubclass(field.annotation, Component)
}
@classmethod

View File

@ -6,14 +6,14 @@ import importlib
import os
import sys
import urllib.parse
from typing import Any, Dict, List, Optional, Set
from typing import Any, Dict, List, Optional, Set, get_args
import pydantic
from reflex_cli.constants.hosting import Hosting
from reflex import constants
from reflex.base import Base
from reflex.utils import console
from reflex.utils import console, types
class DBConfig(Base):
@ -264,14 +264,16 @@ class Config(Base):
# Convert the env var to the expected type.
try:
if issubclass(field.type_, bool):
if types._issubclass(field.annotation, bool):
# special handling for bool values
env_var = env_var.lower() in ["true", "1", "yes"]
elif types.is_generic_alias(field.annotation):
env_var = get_args(field.annotation)[0](env_var)
else:
env_var = field.type_(env_var)
env_var = field.annotation(env_var)
except ValueError:
console.error(
f"Could not convert {key.upper()}={env_var} to type {field.type_}"
f"Could not convert {key.upper()}={env_var} to type {field.annotation}"
)
raise