From 3bc1b535f40b55961fd3b44ff1b38df05e0a9eda Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Mar 2023 01:31:44 +0000 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#354) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Steven Silvester --- .github/scripts/parse_ref.py | 2 +- .pre-commit-config.yaml | 2 +- nbformat/_struct.py | 2 +- nbformat/notebooknode.py | 2 +- nbformat/sign.py | 8 ++++---- nbformat/v2/__init__.py | 4 +--- nbformat/v2/nbpy.py | 2 +- nbformat/v3/__init__.py | 4 +--- nbformat/v3/nbpy.py | 4 ++-- nbformat/validator.py | 16 +++++++++------- pyproject.toml | 2 +- tests/v4/test_json.py | 2 +- 12 files changed, 24 insertions(+), 26 deletions(-) diff --git a/.github/scripts/parse_ref.py b/.github/scripts/parse_ref.py index f27e9187..5b82504d 100644 --- a/.github/scripts/parse_ref.py +++ b/.github/scripts/parse_ref.py @@ -25,7 +25,7 @@ def parse_ref(current_ref): raise Exception(f"Invalid ref `{current_ref}`!") # noqa tag_name = current_ref.replace("refs/tags/", "") - print(tag_name) # noqa + print(tag_name) if __name__ == "__main__": diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f2cbd618..af0fc9ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,7 +35,7 @@ repos: - id: black - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.243 + rev: v0.0.254 hooks: - id: ruff args: ["--fix"] diff --git a/nbformat/_struct.py b/nbformat/_struct.py index 75e816d0..29482155 100644 --- a/nbformat/_struct.py +++ b/nbformat/_struct.py @@ -195,7 +195,7 @@ def __dict_invert(self, data): outdict = {} for k, lst in data.items(): if isinstance(lst, str): - lst = lst.split() + lst = lst.split() # noqa for entry in lst: outdict[entry] = k return outdict diff --git a/nbformat/notebooknode.py b/nbformat/notebooknode.py index 3eb9b8a0..370ee8a9 100644 --- a/nbformat/notebooknode.py +++ b/nbformat/notebooknode.py @@ -23,7 +23,7 @@ def update(self, *args, **kwargs): raise TypeError("update expected at most 1 arguments, got %d" % len(args)) if args: other = args[0] - if isinstance(other, Mapping): + if isinstance(other, Mapping): # noqa for key in other: self[key] = other[key] elif hasattr(other, "keys"): diff --git a/nbformat/sign.py b/nbformat/sign.py index 2e1dbca5..d498bb9a 100644 --- a/nbformat/sign.py +++ b/nbformat/sign.py @@ -596,21 +596,21 @@ def sign_notebook_file(self, notebook_path): def sign_notebook(self, nb, notebook_path=""): """Sign a notebook that's been loaded""" if self.notary.check_signature(nb): - print("Notebook already signed: %s" % notebook_path) # noqa + print("Notebook already signed: %s" % notebook_path) else: - print("Signing notebook: %s" % notebook_path) # noqa + print("Signing notebook: %s" % notebook_path) self.notary.sign(nb) def generate_new_key(self): """Generate a new notebook signature key""" - print("Generating new notebook key: %s" % self.notary.secret_file) # noqa + print("Generating new notebook key: %s" % self.notary.secret_file) self.notary._write_secret_file(os.urandom(1024)) def start(self): """Start the trust notebook app.""" if self.reset: if os.path.exists(self.notary.db_file): - print("Removing trusted signature cache: %s" % self.notary.db_file) # noqa + print("Removing trusted signature cache: %s" % self.notary.db_file) os.remove(self.notary.db_file) self.generate_new_key() return diff --git a/nbformat/v2/__init__.py b/nbformat/v2/__init__.py index d232c71a..430a579c 100644 --- a/nbformat/v2/__init__.py +++ b/nbformat/v2/__init__.py @@ -78,9 +78,7 @@ def parse_filename(fname): The filename, notebook name and format. """ basename, ext = os.path.splitext(fname) - if ext == ".ipynb": - format_ = "json" - elif ext == ".json": + if ext in [".ipynb", ".json"]: format_ = "json" elif ext == ".py": format_ = "py" diff --git a/nbformat/v2/nbpy.py b/nbformat/v2/nbpy.py index 015d7265..f0cde2d1 100644 --- a/nbformat/v2/nbpy.py +++ b/nbformat/v2/nbpy.py @@ -42,7 +42,7 @@ def reads(self, s, **kwargs): """Convert a string to a notebook.""" return self.to_notebook(s, **kwargs) - def to_notebook(self, s, **kwargs): # noqa + def to_notebook(self, s, **kwargs): """Convert a string to a notebook.""" lines = s.splitlines() cells = [] diff --git a/nbformat/v3/__init__.py b/nbformat/v3/__init__.py index 975fd76b..a2686181 100644 --- a/nbformat/v3/__init__.py +++ b/nbformat/v3/__init__.py @@ -86,9 +86,7 @@ def parse_filename(fname): The filename, notebook name and format. """ basename, ext = os.path.splitext(fname) - if ext == ".ipynb": - format_ = "json" - elif ext == ".json": + if ext in [".ipynb", ".json"]: format_ = "json" elif ext == ".py": format_ = "py" diff --git a/nbformat/v3/nbpy.py b/nbformat/v3/nbpy.py index cde4ca43..c9323437 100644 --- a/nbformat/v3/nbpy.py +++ b/nbformat/v3/nbpy.py @@ -113,7 +113,7 @@ def to_notebook(self, s, **kwargs): # noqa nb = new_notebook(worksheets=[ws]) return nb - def new_cell(self, state, lines, **kwargs): # noqa + def new_cell(self, state, lines, **kwargs): """Create a new cell.""" if state == "codecell": input_ = "\n".join(lines) @@ -167,7 +167,7 @@ def split_lines_into_blocks(self, lines): class PyWriter(NotebookWriter): """A Python notebook writer.""" - def writes(self, nb, **kwargs): # noqa + def writes(self, nb, **kwargs): """Convert a notebook to a string.""" lines = ["# -*- coding: utf-8 -*-"] lines.extend( diff --git a/nbformat/validator.py b/nbformat/validator.py index ac9761c9..379781e0 100644 --- a/nbformat/validator.py +++ b/nbformat/validator.py @@ -25,7 +25,9 @@ def _relax_additional_properties(obj): """relax any `additionalProperties`""" if isinstance(obj, dict): for key, value in obj.items(): - value = True if key == "additionalProperties" else _relax_additional_properties(value) + value = ( # noqa + True if key == "additionalProperties" else _relax_additional_properties(value) + ) obj[key] = value elif isinstance(obj, list): for i, value in enumerate(obj): @@ -215,7 +217,7 @@ def __unicode__(self): __str__ = __unicode__ -def better_validation_error(error, version, version_minor): # noqa +def better_validation_error(error, version, version_minor): """Get better ValidationError on oneOf failures oneOf errors aren't informative. @@ -249,10 +251,10 @@ def better_validation_error(error, version, version_minor): # noqa if better.ref is None: better.ref = ref return better - except Exception: + except Exception: # noqa # if it fails for some reason, # let the original error through - pass # noqa + pass return NotebookValidationError(error, ref) @@ -471,7 +473,7 @@ def validate( # noqa version_minor = nbdict_version_minor else: # if ref is specified, and we don't have a version number, assume we're validating against 1.0 - if version is None: + if version is None: # noqa version, version_minor = 1, 0 if ref is None: @@ -518,7 +520,7 @@ def _get_errors( return iter(errors) -def _strip_invalida_metadata( # noqa +def _strip_invalida_metadata( nbdict: Any, version: int, version_minor: int, relax_add_props: bool ) -> int: """ @@ -591,7 +593,7 @@ def _strip_invalida_metadata( # noqa return changes -def iter_validate( # noqa +def iter_validate( nbdict=None, ref=None, version=None, diff --git a/pyproject.toml b/pyproject.toml index aa9c6bee..45773a60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,7 +87,7 @@ dependencies = ["mypy>=0.990"] test = "mypy --install-types --non-interactive {args:nbformat tests}" [tool.hatch.envs.lint] -dependencies = ["black[jupyter]==23.1.0", "mdformat>0.7", "ruff==0.0.243"] +dependencies = ["black[jupyter]==23.1.0", "mdformat>0.7", "ruff==0.0.254"] detached = true [tool.hatch.envs.lint.scripts] style = [ diff --git a/tests/v4/test_json.py b/tests/v4/test_json.py index bfe6c8f4..30c1eec6 100644 --- a/tests/v4/test_json.py +++ b/tests/v4/test_json.py @@ -117,7 +117,7 @@ def test_base_version_matches_latest(self): major=nbformat, minor=nbformat_minor ), ), - ) as schema_file: + ) as schema_file: # noqa ver_schema = json.load(schema_file) assert latest_schema == ver_schema