diff --git a/cantok/tokens/condition_token.py b/cantok/tokens/condition_token.py index d99e8cb..38f5d24 100644 --- a/cantok/tokens/condition_token.py +++ b/cantok/tokens/condition_token.py @@ -57,12 +57,16 @@ def run_function(self) -> bool: return result def text_representation_of_superpower(self) -> str: - result = self.function.__name__ + if hasattr(self.function, '__name__'): + result = self.function.__name__ - if result == '': - return 'λ' + if result == '': + return 'λ' - return result + return result + + else: + return repr(self.function) def get_extra_kwargs(self) -> Dict[str, Any]: result = {} diff --git a/pyproject.toml b/pyproject.toml index 6d39b25..ca2affd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "cantok" -version = "0.0.29" +version = "0.0.30" authors = [ { name="Evgeniy Blinov", email="zheni-b@yandex.ru" }, ] diff --git a/tests/units/tokens/test_condition_token.py b/tests/units/tokens/test_condition_token.py index 2a4fb6a..e6c95ae 100644 --- a/tests/units/tokens/test_condition_token.py +++ b/tests/units/tokens/test_condition_token.py @@ -461,3 +461,17 @@ def function(): return False assert repr(ConditionToken(function, suppress_exceptions=False, default=True)) == 'ConditionToken(function, suppress_exceptions=False, default=True)' assert repr(ConditionToken(function, suppress_exceptions=False, default=True, cancelled=True)) == 'ConditionToken(function, cancelled=True, suppress_exceptions=False, default=True)' + + +def test_repr_for_class_based_function(): + class SomeChecker: + def __call__(self) -> bool: + return True + + def __str__(self) -> str: + return 'str_string' + + def __repr__(self) -> str: + return 'repr_string' + + assert repr(ConditionToken(SomeChecker())) == 'ConditionToken(repr_string)'