Skip to content

[CX-1183] Feat: remove v1 #392

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 2 additions & 6 deletions pythonwhat/checks/check_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
isDefinedCollInProcess,
)
from pythonwhat.checks.check_funcs import part_to_child
from pythonwhat.utils import v2_only
import pandas as pd
import ast

Expand Down Expand Up @@ -155,11 +154,8 @@ def __init__(self, n):
and seeing if the result of running this expression in both student and solution process match.

"""

# Only do the assertion if PYTHONWHAT_V2_ONLY is set to '1'
if v2_only():
extra_msg = "If you want to check the value of an object in e.g. a for loop, use `has_equal_value(name = 'my_obj')` instead."
state.assert_execution_root("check_object", extra_msg=extra_msg)
extra_msg = "If you want to check the value of an object in e.g. a for loop, use `has_equal_value(name = 'my_obj')` instead."
state.assert_execution_root("check_object", extra_msg=extra_msg)

if missing_msg is None:
missing_msg = "Did you define the {{typestr}} `{{index}}` without errors?"
Expand Down
5 changes: 2 additions & 3 deletions pythonwhat/checks/has_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ def has_equal_ast(state, incorrect_msg=None, code=None, exact=True, append=None)
Ex().check_function('numpy.mean').check_args('a').has_equal_ast()

"""
if utils.v2_only():
state.assert_is_not(["object_assignments"], "has_equal_ast", ["check_object"])
state.assert_is_not(["function_calls"], "has_equal_ast", ["check_function"])
state.assert_is_not(["object_assignments"], "has_equal_ast", ["check_object"])
state.assert_is_not(["function_calls"], "has_equal_ast", ["check_function"])

if code and incorrect_msg is None:
raise InstructorError.from_message(
Expand Down
4 changes: 4 additions & 0 deletions pythonwhat/parsing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import ast
import re

from pythonwhat.utils_ast import wrap_in_module
from collections.abc import Sequence, Mapping
from collections import OrderedDict
Expand Down Expand Up @@ -326,13 +328,15 @@ def visit_Dict(self, node):
def visit_Call(self, node):
if self.call_lookup_active:
self.visit(node.func)
self.gen_name += "()"
else:
self.call_lookup_active = True
self.visit(
node.func
) # Need to visit func to start recording the current function name.

if self.gen_name:
self.gen_name = re.sub(r"(?:\(\))+(.)", "\\1", self.gen_name)
if self.gen_name not in self.out:
self.out[self.gen_name] = []

Expand Down
254 changes: 0 additions & 254 deletions pythonwhat/probe.py

This file was deleted.

39 changes: 0 additions & 39 deletions pythonwhat/sct_syntax.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
from protowhat.sct_syntax import EagerChain, ExGen, LazyChainStart, state_dec_gen, LazyChain
from pythonwhat.checks.check_wrappers import scts
from pythonwhat.State import State
from pythonwhat.probe import Node, Probe, TEST_NAMES
from pythonwhat.utils import include_v1
from pythonwhat import test_funcs
from functools import wraps

# TODO: could define scts for check_wrappers at the module level
sct_dict = scts.copy()


def multi_dec(f):
"""Decorator for multi to remove nodes for original test functions from root node"""

@wraps(f)
def wrapper(*args, **kwargs):
args = (
args[0] if len(args) == 1 and isinstance(args[0], (list, tuple)) else args
)
for arg in args:
if isinstance(arg, Node) and arg.parent.name is "root":
arg.parent.remove_child(arg)
arg.update_child_calls()
return f(*args, **kwargs)

return wrapper


state_dec = state_dec_gen(sct_dict)

# todo: __all__?
Expand All @@ -49,22 +27,5 @@ def get_chains():
}


if include_v1():
# Prepare SCTs that may be chained attributes ----------------------
# decorate functions that may try to run test_* function nodes as subtests
# so they remove those nodes from the tree
for k in ["multi", "with_context"]:
sct_dict[k] = multi_dec(sct_dict[k])

# allow test_* functions as chained attributes
for k in TEST_NAMES:
sct_dict[k] = Probe(tree=None, f=getattr(test_funcs, k), eval_on_call=True)

# original logical test_* functions behave like multi
# this is necessary to allow them to take check_* funcs as args
# since probe behavior will try to call all SCTs passed (assuming they're also probes)
for k in ["test_or", "test_correct"]:
sct_dict[k] = multi_dec(getattr(test_funcs, k))

# Prepare check_funcs to be used alone (e.g. test = check_with().check_body())
v2_check_functions = {k: state_dec(v) for k, v in scts.items()}
Loading