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

Start separating normalisation from validation logic #282

Merged
merged 24 commits into from
Aug 16, 2022
Merged
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
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
22 changes: 17 additions & 5 deletions nbformat/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class NBFormatError(ValueError):

def _warn_format():
warnings.warn(
"""Non-JSON file support in nbformat is deprecated.
"""Non-JSON file support in nbformat is deprecated since nbformat 1.0.
Use nbconvert to create files of other formats."""
)

Expand All @@ -107,13 +107,21 @@ def parse_py(s, **kwargs):

def reads_json(nbjson, **kwargs):
"""DEPRECATED, use reads"""
warnings.warn("reads_json is deprecated, use reads")
warnings.warn(
"reads_json is deprecated since nbformat 3.0, use reads",
DeprecationWarning,
stacklevel=2,
)
return reads(nbjson)


def writes_json(nb, **kwargs):
"""DEPRECATED, use writes"""
warnings.warn("writes_json is deprecated, use writes")
warnings.warn(
"writes_json is deprecated since nbformat 3.0, use writes",
DeprecationWarning,
stacklevel=2,
)
return writes(nb, **kwargs)


Expand Down Expand Up @@ -158,7 +166,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 @@ -186,7 +196,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