use typing.get_args instead of __args__

This commit is contained in:
Benedikt Bartscher 2024-03-02 11:28:43 +01:00
parent 3c30ceb7f7
commit bcd29a10e6
No known key found for this signature in database

View File

@ -18,6 +18,7 @@ from typing import (
Set, Set,
Type, Type,
Union, Union,
get_args,
) )
from pydantic.fields import ModelPrivateAttr from pydantic.fields import ModelPrivateAttr
@ -299,7 +300,7 @@ class Component(BaseComponent, ABC):
if kwargs[key] is None: if kwargs[key] is None:
raise TypeError raise TypeError
expected_type = field_type.__args__[0] expected_type = get_args(field_type)[0]
# validate literal fields. # validate literal fields.
types.validate_literal( types.validate_literal(
key, value, expected_type, type(self).__name__ key, value, expected_type, type(self).__name__
@ -1392,7 +1393,7 @@ class CustomComponent(Component):
def custom_component( def custom_component(
component_fn: Callable[..., Component] component_fn: Callable[..., Component],
) -> Callable[..., CustomComponent]: ) -> Callable[..., CustomComponent]:
"""Create a custom component from a function. """Create a custom component from a function.