Skip to content

Commit

Permalink
handling lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme1 committed Jul 5, 2023
1 parent 776b24c commit a51aff9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions connectome/interface/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,17 @@ def _collect_nodes(self):
is_argument = False
if callable(value):
# 1. a callable argument without annotation: x = some_func
inside_body = getattr(value, '__qualname__', '').startswith(self.name)
qualname = getattr(value, '__qualname__', '')
# if we can't detect this better not to annoy the user
inside_body = None
if qualname.count('.') >= 1:
scope, func_name = qualname.rsplit('.', 1)
# lambdas are a special case. don't know what to do with them
if func_name != '<lambda>':
inside_body = scope.endswith(self.name)

if name not in annotations:
if not inside_body:
if inside_body is not None and not inside_body:
warnings.warn(
f'The parameter {name} is defined outside of the class body. Are you trying to pass '
f'a default value for an argument? If so, add a type annotation: "{name}: Callable = ..."',
Expand All @@ -219,7 +227,7 @@ def _collect_nodes(self):
# a function defined inside the body, which also has a type annotation
else:
is_argument = True
if inside_body:
if inside_body is not None and inside_body:
warnings.warn(
f'The default value for the argument {name} is a function, defined inside of the '
f'class body. Did you forget to remove the type annotation?',
Expand Down

0 comments on commit a51aff9

Please sign in to comment.