Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed a typo #94

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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