Skip to content

Commit 62e12eb

Browse files
committed
fix: address fixes
1 parent 7923685 commit 62e12eb

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/ape/api/convert.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from abc import abstractmethod
2-
from typing import Any, Generic, Optional, TypeVar
1+
from abc import ABC, abstractmethod
2+
from typing import Any, Generic, TypeVar
33

4-
from ape.exceptions import APINotImplementedError
54
from ape.utils.basemodel import BaseInterfaceModel
65

76
ConvertedType = TypeVar("ConvertedType")
@@ -59,16 +58,20 @@ def name(self) -> str:
5958
return name.lower()
6059

6160

62-
class ConvertibleAPI:
61+
class ConvertibleAPI(ABC):
6362
"""
6463
Use this base-class mixin if you want your custom class to be convertible to a more basic type
6564
without having to register a converter plugin for it.
6665
"""
6766

67+
@abstractmethod
6868
def is_convertible(self, to_type: type) -> bool:
69-
return False
69+
"""
70+
Returns ``True`` if ``self`` can be converted to ``to_type``.
71+
"""
7072

71-
def convert_to(self, to_type: type) -> Optional[Any]:
72-
raise APINotImplementedError(
73-
f"Unable to convert '{self.__class__.__name__}' to type '{to_type.__class__.__name__}'."
74-
)
73+
@abstractmethod
74+
def convert_to(self, to_type: type) -> Any:
75+
"""
76+
Convert ``self`` to the given type. Raises ``ConversionError`` if not convertible.
77+
"""

src/ape/managers/converters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def convert(self, value: Any, to_type: Union[type, tuple, list]) -> Any:
365365
# NOTE: Always process lists and tuples
366366
return value
367367

368-
if isinstance(value, ConvertibleAPI) is value.is_convertible(to_type):
368+
if isinstance(value, ConvertibleAPI) and value.is_convertible(to_type):
369369
return value.convert_to(to_type)
370370

371371
return self._convert_using_converter_apis(value, to_type)

0 commit comments

Comments
 (0)