Skip to content

Commit

Permalink
Clean up lint handling and list generics (#2065)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Nov 5, 2023
1 parent 0e290e1 commit 422dd2a
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
hatch run lint:build
pipx run interrogate -v .
pipx run doc8 --max-line-length=200 --ignore-path=docs/source/other/full-config.rst
Expand Down
27 changes: 25 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.0
rev: 0.27.1
hooks:
- id: check-github-workflows

Expand Down Expand Up @@ -50,6 +50,29 @@ repos:
- id: codespell
args: ["-L", "sur,nd"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.6.1"
hooks:
- id: mypy
files: "^nbconvert"
stages: [manual]
args: ["--install-types", "--non-interactive"]
additional_dependencies:
[
"traitlets>=5.13",
"jupyter_core>=5.3",
"jinja2",
"nbformat",
"markupsafe",
"mistune",
"nbclient",
"defusedxml",
"ipython",
"packaging",
"pandocfilters",
"jupyterlab_pygments",
]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
Expand All @@ -58,7 +81,7 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
rev: v0.1.4
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down
10 changes: 4 additions & 6 deletions nbconvert/exporters/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ class Exporter(LoggingConfigurable):
export_from_notebook: str = None # type:ignore[assignment]

# Configurability, allows the user to easily add filters and preprocessors.
preprocessors: List[str] = List(
preprocessors: List[t.Any] = List(
help="""List of preprocessors, by name or namespace, to enable."""
).tag( # type:ignore[assignment]
config=True
)
).tag(config=True)

_preprocessors: List[str] = List()
_preprocessors: List[t.Any] = List()

default_preprocessors: List[t.Any] = List(
[
Expand Down Expand Up @@ -351,7 +349,7 @@ def _preprocess(self, nb, resources):
# Run each preprocessor on the notebook. Carry the output along
# to each preprocessor
for preprocessor in self._preprocessors:
nbc, resc = preprocessor(nbc, resc) # type:ignore[operator]
nbc, resc = preprocessor(nbc, resc)
if not self.optimistic_validation:
self._validate_preprocessor(nbc, preprocessor)

Expand Down
2 changes: 1 addition & 1 deletion nbconvert/exporters/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PDFExporter(LatexExporter):

output_mimetype = "application/pdf"

_captured_output: List[str] = List()
_captured_output = List(Unicode())

@default("file_extension")
def _file_extension_default(self):
Expand Down
8 changes: 4 additions & 4 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ def _raw_template_changed(self, change):
self._invalidate_template_cache()

template_paths = List(["."]).tag(config=True, affects_environment=True)
extra_template_basedirs: List[str] = List().tag(config=True, affects_environment=True) # type:ignore[assignment]
extra_template_paths: List[str] = List([]).tag(config=True, affects_environment=True) # type:ignore[assignment]
extra_template_basedirs = List(Unicode()).tag(config=True, affects_environment=True)
extra_template_paths = List(Unicode()).tag(config=True, affects_environment=True)

@default("extra_template_basedirs")
def _default_extra_template_basedirs(self):
Expand Down Expand Up @@ -327,8 +327,8 @@ def _template_extension_default(self):
environment."""
).tag(config=True, affects_environment=True)

raw_mimetypes: List[str] = List( # type:ignore[assignment]
help="""formats of raw cells to be included in this Exporter's output."""
raw_mimetypes = List(
Unicode(), help="""formats of raw cells to be included in this Exporter's output."""
).tag(config=True)

@default("raw_mimetypes")
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ def _postprocessor_class_changed(self, change):
``Exporter`` class""",
).tag(config=True)

notebooks: List[str] = List( # type:ignore[assignment]
[],
notebooks = List(
Unicode(),
help="""List of notebooks to convert.
Wildcards are supported.
Filenames passed positionally will be added to the list.
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/preprocessors/regexremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class RegexRemovePreprocessor(Preprocessor):
documentation in python.
"""

patterns: List[str] = List(Unicode(), default_value=[]).tag(config=True) # type:ignore[misc]
patterns = List(Unicode()).tag(config=True)

def check_conditions(self, cell):
"""
Expand Down
6 changes: 3 additions & 3 deletions nbconvert/writers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Distributed under the terms of the Modified BSD License.
from __future__ import annotations

from traitlets import List
from traitlets import List, Unicode

from nbconvert.utils.base import NbConvertBase

Expand All @@ -15,8 +15,8 @@ class WriterBase(NbConvertBase):
"""Consumes output from nbconvert export...() methods and writes to a
useful location."""

files: List[str] = List( # type:ignore[assignment]
[],
files = List(
Unicode(),
help="""
List of the files that the notebook references. Files will be
included with written output.""",
Expand Down
33 changes: 10 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,37 +111,24 @@ dependencies = ["coverage[toml]", "pytest-cov"]
test = "python -m pytest -vv --cov nbconvert --cov-branch --cov-report term-missing:skip-covered {args}"
nowarn = "test -W default {args}"

[tool.hatch.envs.typing]
features = ["test"]
dependencies = ["mypy~=1.6", "traitlets>=5.13.0", "jupyter_core>=5.3.2"]
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args}"

[tool.hatch.envs.lint]
dependencies = [
"mdformat>0.7",
"mdformat-gfm>=0.3.5",
"ruff==0.1.3"
]
detached = true
dependencies = ["pre-commit"]
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"ruff format {args:.}",
"mdformat --check {args:docs *.md}"
]
fmt = [
"ruff --fix {args:.}",
"ruff format {args:.}",
"mdformat {args:docs *.md}"
]
build = "pre-commit run --all-files ruff"

[tool.hatch.envs.typing]
dependencies = [ "pre-commit"]
detached = true
[tool.hatch.envs.typing.scripts]
test = "pre-commit run --all-files --hook-stage manual mypy"

[tool.pytest.ini_options]
minversion = "6.0"
xfail_strict = true
log_cli_level = "info"
addopts = [
"-raXs", "--durations=10", "--color=yes", "--doctest-modules",
"-ra", "--durations=10", "--color=yes", "--doctest-modules",
"--showlocals", "--strict-markers", "--strict-config",
"--ignore=tests/files/jupyter_nbconvert_config.py",
"--ignore=tests/files/override.py",
Expand Down Expand Up @@ -255,7 +242,7 @@ fail-under=100
exclude = ["tests", "docs"]

[tool.repo-review]
ignore = ["PY007", "PP308", "GH102", "PC140"]
ignore = ["PY007", "GH102"]


[tool.codespell]
Expand Down

0 comments on commit 422dd2a

Please sign in to comment.