Skip to content

Commit bc492e4

Browse files
committed
fix: modify type check to accept Callable (GoogleCloudPlatform#317)
In the get_user_function function within _function_registry.py, change the type check to accept callable objects instead of only types.FunctionType. This allows for instances of classes with a __call__ method.
1 parent 7ff9e38 commit bc492e4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/functions_framework/_function_registry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import types
1818

1919
from re import T
20-
from typing import Type
20+
from typing import Type, Callable
2121

2222
from functions_framework.exceptions import (
2323
InvalidConfigurationException,
@@ -57,11 +57,11 @@ def get_user_function(source, source_module, target):
5757
)
5858
)
5959
function = getattr(source_module, target)
60-
# Check that it is a function
61-
if not isinstance(function, types.FunctionType):
60+
# Check that it is callable.
61+
if not isinstance(function, Callable):
6262
raise InvalidTargetTypeException(
6363
"The function defined in file {source} as '{target}' needs to be of "
64-
"type function. Got: invalid type {target_type}".format(
64+
"type Callable. Got: invalid type {target_type}".format(
6565
source=source, target=target, target_type=type(function)
6666
)
6767
)

0 commit comments

Comments
 (0)