Skip to content

Commit

Permalink
Merge pull request #282 from Carreau/nbv2
Browse files Browse the repository at this point in the history
Start separating normalisation from validation logic
  • Loading branch information
Carreau authored Aug 16, 2022
2 parents b23aad6 + fc45fed commit 1b5c839
Show file tree
Hide file tree
Showing 7 changed files with 619 additions and 99 deletions.
12 changes: 12 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ Changes in nbformat
In Development
==============

The biggest change in nbformat 5.5.0 is the deprecation of arguments to
``validate()`` that try to fix notebooks errors during validation.

``validate()`` is a function that is core to the security model of Jupyter,
and is assumed in a number of places to not mutate it's argument, or try to fix
notebooks passed to it.

Auto fixing of notebook in validate can also hide subtle bugs, and will
therefore be updated in a near future to not take any of the argument related to
auto-fixing, and fail instead of silently modifying its parameters on invalid
notebooks.

5.4.0
=====
* Add project URLs to ``setup.py``
Expand Down
8 changes: 6 additions & 2 deletions nbformat/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def reads(s, format="DEPRECATED", version=current_nbformat, **kwargs):
nb = reader_reads(s, **kwargs)
nb = convert(nb, version)
try:
validate(nb)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
validate(nb, repair_duplicate_cell_ids=False)
except ValidationError as e:
get_logger().error("Notebook JSON is invalid: %s", e)
return nb
Expand Down Expand Up @@ -195,7 +197,9 @@ def writes(nb, format="DEPRECATED", version=current_nbformat, **kwargs):
_warn_format()
nb = convert(nb, version)
try:
validate(nb)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
validate(nb, repair_duplicate_cell_ids=False)
except ValidationError as e:
get_logger().error("Notebook JSON is invalid: %s", e)
return versions[version].writes_json(nb, **kwargs)
Expand Down
2 changes: 2 additions & 0 deletions nbformat/json_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def _validator_for_name(validator_name):
for (name, module, validator_cls) in _VALIDATOR_MAP:
if module and validator_name == name:
return validator_cls
# we always return something.
raise ValueError(f"Missing validator for {repr(validator_name)}")


def get_current_validator():
Expand Down
Loading

0 comments on commit 1b5c839

Please sign in to comment.