replace type_ and outer_type_ with field.annotation
This commit is contained in:
parent
62d36bfecc
commit
c7eda15470
@ -194,7 +194,7 @@ class Component(BaseComponent, ABC):
|
|||||||
ValueError: If a prop value is invalid.
|
ValueError: If a prop value is invalid.
|
||||||
"""
|
"""
|
||||||
# Set the id and children initially.
|
# Set the id and children initially.
|
||||||
children = kwargs.get("children", [])
|
kwargs.get("children", [])
|
||||||
# kwargs = {
|
# kwargs = {
|
||||||
# **{
|
# **{
|
||||||
# prop: Var.create(None) if field.is_required() and types._issubclass(field.annotation, Var) else field.default
|
# 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
|
name
|
||||||
for name, field in cls.get_fields().items()
|
for name, field in cls.get_fields().items()
|
||||||
if name in cls.get_props()
|
if name in cls.get_props()
|
||||||
and types._issubclass(field.outer_type_, Component)
|
and types._issubclass(field.annotation, Component)
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -6,14 +6,14 @@ import importlib
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from typing import Any, Dict, List, Optional, Set
|
from typing import Any, Dict, List, Optional, Set, get_args
|
||||||
|
|
||||||
import pydantic
|
import pydantic
|
||||||
from reflex_cli.constants.hosting import Hosting
|
from reflex_cli.constants.hosting import Hosting
|
||||||
|
|
||||||
from reflex import constants
|
from reflex import constants
|
||||||
from reflex.base import Base
|
from reflex.base import Base
|
||||||
from reflex.utils import console
|
from reflex.utils import console, types
|
||||||
|
|
||||||
|
|
||||||
class DBConfig(Base):
|
class DBConfig(Base):
|
||||||
@ -264,14 +264,16 @@ class Config(Base):
|
|||||||
|
|
||||||
# Convert the env var to the expected type.
|
# Convert the env var to the expected type.
|
||||||
try:
|
try:
|
||||||
if issubclass(field.type_, bool):
|
if types._issubclass(field.annotation, bool):
|
||||||
# special handling for bool values
|
# special handling for bool values
|
||||||
env_var = env_var.lower() in ["true", "1", "yes"]
|
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:
|
else:
|
||||||
env_var = field.type_(env_var)
|
env_var = field.annotation(env_var)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
console.error(
|
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
|
raise
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user