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

Check for multiple lambdas in add_functions analysis #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions problem_db/add_functions.tut/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ class CodeVisitor(TutorialNodeVisitor):
def __init__(self):
super().__init__()

self.uses_lambda = False
self.lambda_count = 0
self.num_lambda_args = None
self.adds_in_lambda = False

def visit_Lambda(self, node):
super().visit_Lambda(node)

self.uses_lambda = True
self.lambda_count += 1
self.num_lambda_args = len(node.args.args)

if isinstance(node.body, ast.BinOp) \
Expand All @@ -25,8 +25,10 @@ def _analyse(self):
self.add_error('add_functions should accept exactly two args')
else:
# some of these are only safe if the function is defined properly
if not self.visitor.uses_lambda:
if self.visitor.lambda_count == 0:
self.add_error('You need to use a lambda function')
elif self.visitor.lambda_count > 1:
self.add_error('You only need to define one lambda function')
elif self.visitor.num_lambda_args != 1:
self.add_error('Your lambda should only take in a single arg')
elif not self.visitor.adds_in_lambda:
Expand Down