Пример #1
0
def validate_user_constants(*allow_types):
    return All(
        has_keys_of_type(six.string_types),
        coerce_string_keys_to_text_type,
        {Extra: Any(*allow_types)},
    )
Пример #2
0
def validate_user_constants(*allow_types):
    return All(
        has_keys_of_type(str),
        {Extra: Any(*allow_types)},
    )
Пример #3
0
                    raise ConfigError(
                        "DependentSamplers depend on undefined quantities: " +
                        bad_symbols)

                # 2: Circular dependencies
                bad_symbols = ", ".join(sorted(unevaluated_dependents.keys()))
                raise ConfigError(
                    "Circularly dependent DependentSamplers detected: " +
                    bad_symbols)

        sample_list.append(sample_dict)
    return sample_list


# Used by NumericalGrader
schema_user_functions_no_random = All(has_keys_of_type(six.string_types),
                                      coerce_string_keys_to_text_type,
                                      {Extra: is_callable})
# Used by FormulaGrader and friends
schema_user_functions = All(
    has_keys_of_type(six.string_types),
    coerce_string_keys_to_text_type,
    {
        Extra:
        Any(is_callable, All([is_callable], Coerce(SpecificFunctions)),
            FunctionSamplingSet)
    },
)


def construct_functions(default_functions, user_funcs):
Пример #4
0
                        sample_dict, functions, suffixes)
                    del unevaluated_dependents[symbol]
                    progress_made = True

            if not progress_made:
                bad_symbols = ", ".join(sorted(unevaluated_dependents.keys()))
                raise ConfigError(
                    "Circularly dependent DependentSamplers detected: " +
                    bad_symbols)

        sample_list.append(sample_dict)
    return sample_list


schema_user_functions = All(
    has_keys_of_type(str),
    {
        Extra:
        Any(is_callable, All([is_callable], Coerce(SpecificFunctions)),
            FunctionSamplingSet)
    },
)


def construct_functions(default_functions, user_funcs):
    """
    Constructs functions for use in sampling math expressions.

    Arguments:
        default_funcs: a dict mapping function names (strings) to functions
        user_funcs: a dict mapping function names (strings) to functions OR