text
stringlengths
0
828
typ = _guess_type_from_validator(v)
if typ is not None:
return typ
return None
elif isinstance(validator, _InstanceOfValidator):
# InstanceOf validator : found it !
return validator.type
else:
# we could not find the type
return None"
1156,"def is_optional(attr):
""""""
Helper method to find if an attribute is mandatory
:param attr:
:return:
""""""
return isinstance(attr.validator, _OptionalValidator) or (attr.default is not None and attr.default is not NOTHING)"
1157,"def get_attrs_declarations(item_type):
""""""
Helper method to return a dictionary of tuples. Each key is attr_name, and value is (attr_type, attr_is_optional)
:param item_type:
:return:
""""""
# this will raise an error if the type is not an attr-created type
attribs = fields(item_type)
res = dict()
for attr in attribs:
attr_name = attr.name
# -- is the attribute mandatory ?
optional = is_optional(attr)
# -- get and check the attribute type
typ = guess_type_from_validators(attr)
# -- store both info in result dict
res[attr_name] = (typ, optional)
return res"
1158,"def preprocess(
self, nb: ""NotebookNode"", resources: dict
) -> Tuple[""NotebookNode"", dict]:
""""""Remove any raw cells from the Notebook.
By default, exclude raw cells from the output. Change this by including
global_content_filter->include_raw = True in the resources dictionary.
This preprocessor is necessary because the NotebookExporter doesn't
include the exclude_raw config.""""""
if not resources.get(""global_content_filter"", {}).get(""include_raw"", False):
keep_cells = []
for cell in nb.cells:
if cell.cell_type != ""raw"":
keep_cells.append(cell)
nb.cells = keep_cells
return nb, resources"
1159,"def preprocess(
self, nb: ""NotebookNode"", resources: dict
) -> Tuple[""NotebookNode"", dict]:
""""""Preprocess the entire notebook.""""""
if ""remove_solution"" not in resources:
raise KeyError(""The resources dictionary must have a remove_solution key."")
if resources[""remove_solution""]:
keep_cells_idx = []
for index, cell in enumerate(nb.cells):
if ""## solution"" in cell.source.lower():
keep_cells_idx.append(index)
# The space at the end of the test string here is important
elif len(keep_cells_idx) > 0 and cell.source.startswith(""### ""):
keep_cells_idx.append(index)
keep_cells = nb.cells[: keep_cells_idx[0] + 1]
for i in keep_cells_idx[1:]:
keep_cells.append(nb.cells[i])
if resources[""by_hand""]:
keep_cells.append(by_hand_cell)
else:
if ""sketch"" in nb.cells[i].source.lower():
keep_cells.append(sketch_cell)
else:
keep_cells.append(md_expl_cell)
keep_cells.append(code_ans_cell)
keep_cells.append(md_ans_cell)
nb.cells = keep_cells
return nb, resources"
1160,"def preprocess(
self, nb: ""NotebookNode"", resources: dict
) -> Tuple[""NotebookNode"", dict]:
""""""Preprocess the entire Notebook.""""""
for index, cell in enumerate(nb.cells):
if ""## Solution"" in cell.source:
nb.cells[index + 1].source = """"