From 48599a4bba00819e4e626fe098eb204977590ee4 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 30 Oct 2023 07:08:55 -0500 Subject: [PATCH] Fix typing for traitlets 5.13 (#2060) --- nbconvert/exporters/exporter.py | 10 ++++++---- nbconvert/exporters/pdf.py | 3 ++- nbconvert/exporters/templateexporter.py | 8 ++++---- nbconvert/nbconvertapp.py | 2 +- nbconvert/preprocessors/regexremove.py | 3 ++- nbconvert/preprocessors/sanitize.py | 4 ++-- nbconvert/writers/base.py | 3 ++- pyproject.toml | 2 +- 8 files changed, 20 insertions(+), 15 deletions(-) diff --git a/nbconvert/exporters/exporter.py b/nbconvert/exporters/exporter.py index 5b7793176..ac126ee89 100644 --- a/nbconvert/exporters/exporter.py +++ b/nbconvert/exporters/exporter.py @@ -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", @@ -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) diff --git a/nbconvert/exporters/pdf.py b/nbconvert/exporters/pdf.py index 7e15a9b47..e83495473 100644 --- a/nbconvert/exporters/pdf.py +++ b/nbconvert/exporters/pdf.py @@ -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 @@ -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): diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py index ab69bfe61..9c65642ce 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -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): @@ -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) @@ -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) diff --git a/nbconvert/nbconvertapp.py b/nbconvert/nbconvertapp.py index dc712c101..2766e1bf9 100755 --- a/nbconvert/nbconvertapp.py +++ b/nbconvert/nbconvertapp.py @@ -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. diff --git a/nbconvert/preprocessors/regexremove.py b/nbconvert/preprocessors/regexremove.py index 1aef0498f..eb5dd5128 100644 --- a/nbconvert/preprocessors/regexremove.py +++ b/nbconvert/preprocessors/regexremove.py @@ -5,6 +5,7 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. +from __future__ import annotations import re @@ -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): """ diff --git a/nbconvert/preprocessors/sanitize.py b/nbconvert/preprocessors/sanitize.py index a9e9f20c1..0882a955b 100644 --- a/nbconvert/preprocessors/sanitize.py +++ b/nbconvert/preprocessors/sanitize.py @@ -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