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

ok does not pass the nosetests #380

Closed
kavigupta opened this issue Nov 2, 2019 · 4 comments · Fixed by #381
Closed

ok does not pass the nosetests #380

kavigupta opened this issue Nov 2, 2019 · 4 comments · Fixed by #381

Comments

@kavigupta
Copy link
Contributor

I think I've tracked the error down to b605ed3#diff-c66760f0a6aa193db7eca384468b2da0 by @jathak

@jathak do you remember what you were doing in this PR? I'm pretty sure that ast.literal_eval can't handle the string "[1,2,3,2+2]" since it can't handle binary operations.

python
Python 3.7.2 (default, Dec 29 2018, 06:19:36) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.literal_eval("2+2")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kavi/anaconda3/envs/py37/lib/python3.7/ast.py", line 91, in literal_eval
    return _convert(node_or_string)
  File "/home/kavi/anaconda3/envs/py37/lib/python3.7/ast.py", line 90, in _convert
    return _convert_signed_num(node)
  File "/home/kavi/anaconda3/envs/py37/lib/python3.7/ast.py", line 63, in _convert_signed_num
    return _convert_num(node)
  File "/home/kavi/anaconda3/envs/py37/lib/python3.7/ast.py", line 55, in _convert_num
    raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.BinOp object at 0x7f32460ee4e0>
@jathak
Copy link
Contributor

jathak commented Nov 2, 2019

IIRC, Ok originally did exact string matching for unlocking questions, which caused issues when students entered responses that were correct, but not in the canonical form (e.g. [1,2,3] instead of [1, 2, 3]). At first, we tried to fix this by evaling the student response (in #101), but that was too lenient (see #211), so #223 replaced eval there with ast.literal_eval, which was the closest thing to expression canonicalization we could find in the standard library.

@jathak
Copy link
Contributor

jathak commented Nov 2, 2019

Perhaps ast.literal_evals semantics changed between Python versions?

@kavigupta
Copy link
Contributor Author

Ah that must be it since sumukh said "For future reference: ast.literal_eval supports addition/subtraction of integers (but not other operations/other types" on the PR

@kavigupta
Copy link
Contributor Author

Yep: https://bugs.python.org/issue31778

Ok I'll change the test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants