Skip to content

Commit

Permalink
Merge pull request #94 from neuro-ml/dev
Browse files Browse the repository at this point in the history
fixed a typo
  • Loading branch information
maxme1 authored Jul 5, 2023
2 parents d998a6c + e3ad90b commit 4084679
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion connectome/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.0'
__version__ = '0.7.1'
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 not 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
5 changes: 4 additions & 1 deletion tests/test_interface/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ def x(_a):
with warnings.catch_warnings():
warnings.filterwarnings('error')
with pytest.raises(UserWarning, match='Are you trying to pass a default value for an argument?'):
def _a():
pass

class B(Transform):
_a = lambda: []
_b = _a

with pytest.raises(UserWarning, match='Did you forget to remove the type annotation?'):
class C(Transform):
Expand Down

0 comments on commit 4084679

Please sign in to comment.