Skip to content

Commit

Permalink
fix: modify type check to accept Callable (GoogleCloudPlatform#317)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
junah201 committed Apr 11, 2024
1 parent 7ff9e38 commit bc492e4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/functions_framework/_function_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import types

from re import T
from typing import Type
from typing import Type, Callable

from functions_framework.exceptions import (
InvalidConfigurationException,
Expand Down Expand Up @@ -57,11 +57,11 @@ def get_user_function(source, source_module, target):
)
)
function = getattr(source_module, target)
# Check that it is a function
if not isinstance(function, types.FunctionType):
# Check that it is callable.
if not isinstance(function, Callable):
raise InvalidTargetTypeException(
"The function defined in file {source} as '{target}' needs to be of "
"type function. Got: invalid type {target_type}".format(
"type Callable. Got: invalid type {target_type}".format(
source=source, target=target, target_type=type(function)
)
)
Expand Down

0 comments on commit bc492e4

Please sign in to comment.