Skip to content

Commit

Permalink
Fix typing for traitlets 5.13 (#2060)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Oct 30, 2023
1 parent 9df32d6 commit 48599a4
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
10 changes: 6 additions & 4 deletions nbconvert/exporters/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ class Exporter(LoggingConfigurable):
export_from_notebook: str = None # type:ignore[assignment]

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

_preprocessors = List()
_preprocessors: List[str] = List()

default_preprocessors = List(
default_preprocessors: List[t.Any] = List(
[
"nbconvert.preprocessors.TagRemovePreprocessor",
"nbconvert.preprocessors.RegexRemovePreprocessor",
Expand Down Expand Up @@ -349,7 +351,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)
nbc, resc = preprocessor(nbc, resc) # type:ignore[operator]
if not self.optimistic_validation:
self._validate_preprocessor(nbc, preprocessor)

Expand Down
3 changes: 2 additions & 1 deletion nbconvert/exporters/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
from __future__ import annotations

import os
import shutil
Expand Down Expand Up @@ -74,7 +75,7 @@ class PDFExporter(LatexExporter):

output_mimetype = "application/pdf"

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

@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().tag(config=True, affects_environment=True)
extra_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]

@default("extra_template_basedirs")
def _default_extra_template_basedirs(self):
Expand Down Expand Up @@ -317,7 +317,7 @@ def _template_extension_default(self):
False, help="This allows you to exclude unknown cells from all templates if set to True."
).tag(config=True)

extra_loaders = List(
extra_loaders: List[t.Any] = List(
help="Jinja loaders to find templates. Will be tried in order "
"before the default FileSystem ones.",
).tag(affects_environment=True)
Expand All @@ -327,7 +327,7 @@ def _template_extension_default(self):
environment."""
).tag(config=True, affects_environment=True)

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

Expand Down
2 changes: 1 addition & 1 deletion nbconvert/nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _postprocessor_class_changed(self, change):
``Exporter`` class""",
).tag(config=True)

notebooks = List(
notebooks: List[str] = List( # type:ignore[assignment]
[],
help="""List of notebooks to convert.
Wildcards are supported.
Expand Down
3 changes: 2 additions & 1 deletion nbconvert/preprocessors/regexremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
from __future__ import annotations

import re

Expand Down Expand Up @@ -38,7 +39,7 @@ class RegexRemovePreprocessor(Preprocessor):
documentation in python.
"""

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

def check_conditions(self, cell):
"""
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/preprocessors/sanitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ class SanitizeHTML(Preprocessor):
tags = List(
Unicode(),
config=True,
default_value=ALLOWED_TAGS,
default_value=ALLOWED_TAGS, # type:ignore[arg-type]
help="List of HTML tags to allow",
)
styles = List(
Unicode(),
config=True,
default_value=ALLOWED_STYLES,
default_value=ALLOWED_STYLES, # type:ignore[arg-type]
help="Allowed CSS styles if <style> tag is allowed",
)
strip = Bool(
Expand Down
3 changes: 2 additions & 1 deletion nbconvert/writers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from __future__ import annotations

from traitlets import List

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

files = List(
files: List[str] = List( # type:ignore[assignment]
[],
help="""
List of the files that the notebook references. Files will be
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ nowarn = "test -W default {args}"

[tool.hatch.envs.typing]
features = ["test"]
dependencies = ["mypy~=1.6", "traitlets>=5.11.2", "jupyter_core>=5.3.2"]
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}"

Expand Down

0 comments on commit 48599a4

Please sign in to comment.