alexander-bauer/swirlypy

NewVariableQuestion reaches exception

alexander-bauer opened this issue · 5 comments

Here we create a variable for use in subsequent questions. Set x=10
Press CTRL-D to submit.
>>> 
set()
Traceback (most recent call last):
  File "utils/swirlytool.py", line 115, in <module>
    sys.exit(main(parse(sys.argv[1:])))
  File "utils/swirlytool.py", line 86, in main
    args.func(args)
  File "utils/swirlytool.py", line 41, in run
    course.execute()
  File "/home/sasha/dev/python/swirlypy/course.py", line 120, in execute
    self.execute_lesson(identifier)
  File "/home/sasha/dev/python/swirlypy/course.py", line 139, in execute_lesson
    data = lesson.execute()
  File "/home/sasha/dev/python/swirlypy/lesson.py", line 20, in execute
    new_data = question.execute(data=data)
  File "/home/sasha/dev/python/swirlypy/question.py", line 117, in execute
    testresult = self.test_response(resp, data=data)
  File "/home/sasha/dev/python/swirlypy/questions/NewVariable.py", line 20, in test_response
    for newval in mustaddvals:
TypeError: 'int' object is not iterable

If this happened with tricky.yaml, as I suspect, I should note that tricky.yaml is obsolete. Actually, it was never meant to work so much as to demonstrate the kinds of things which needed support. Even so, the type error is unexpected and seems worth understanding.

Something equivalent to tricky.yaml should work with specialized subclasses of ReportingQuestions, but I wanted to wait for course-based subclass loading before doing that.

It's a problem with tricky.yaml, not with python code. The variables field of a NewVariable question should be iterable. The original, as follows, is not:

- Category: newvariable
  Output: "Here we create a variable for use in subsequent questions. Set x=10"
  Answer: x = 10
  Hint: "Enter x = 10"
  Variables: 10

But making variables a list fixes the problem (although it should probably say ['x'] not [10].)

- Category: newvariable
  Output: "Here we create a variable for use in subsequent questions. Set x=10"
  Answer: x = 10
  Hint: "Enter x = 10"
  Variables: [10]

I'd favor chucking tricky.yaml and moving any yaml material still deemed useful out of the swirlypy package.

Pending the following two developments, I believe we could begin to write serious course material

  1. a sanity-checked version of RecordingQuestion merged into master,
  2. course-based question subclasses

R swirl experience suggests that few rough equivalents of question subclasses are broadly applicable. Some, which appear first in contexts specific to lessons, turn out to be very useful, and are incorporated into the package after their general utility becomes apparent.

Right, thank you for investigating this. It demonstates a weakness in NewVariable. We need to rewrite it, anyway, but I'd like to make it more robust.

NewVariable has been rewritten and obsolete lessons removed. Closing.