Skip to content

Commit

Permalink
fix is_component_class check
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgerrits committed Jan 12, 2025
1 parent 8c704f3 commit 21d65d5
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import importlib
import warnings
from abc import ABC, abstractmethod
from typing import Any, ClassVar, Dict, Generic, Literal, Type, cast, overload, runtime_checkable
from typing import Any, ClassVar, Dict, Generic, Literal, Type, cast, overload

from pydantic import BaseModel
from typing_extensions import Self, TypeVar
Expand Down Expand Up @@ -213,7 +213,7 @@ def load_component(
module = importlib.import_module(module_path)
component_class = cast(Component[BaseModel], module.__getattribute__(class_name))

if not isinstance(component_class, Component):
if not is_component_class(component_class):
raise TypeError("Invalid component class")

# We need to check the schema is valid
Expand Down Expand Up @@ -310,10 +310,15 @@ def _from_config(cls, config: Config) -> MyComponent:
...


def is_component_class(cls: type) -> bool:
def is_component_class(cls: type | Any) -> bool:
return (
issubclass(cls, ComponentFromConfig)
and issubclass(cls, ComponentToConfig)
and issubclass(cls, ComponentSchemaType)
and issubclass(cls, ComponentLoader)
) or (
isinstance(cls, ComponentFromConfig)
and isinstance(cls, ComponentToConfig)
and isinstance(cls, ComponentSchemaType)
and isinstance(cls, ComponentLoader)
)

0 comments on commit 21d65d5

Please sign in to comment.