mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add missing type stubs (#12619)
Co-authored-by: Daniel Eades <daniel.eades@seebyte.com>
This commit is contained in:
@@ -86,7 +86,10 @@ lint = [
|
||||
"ruff==0.5.2",
|
||||
"mypy==1.10.1",
|
||||
"sphinx-lint>=0.9",
|
||||
"types-colorama==0.4.15.20240311",
|
||||
"types-docutils==0.21.0.20240711",
|
||||
"types-Pillow==10.2.0.20240520",
|
||||
"types-Pygments==2.18.0.20240506",
|
||||
"types-requests>=2.30.0", # align with requests
|
||||
"importlib-metadata>=6.0", # for mypy (Python<=3.9)
|
||||
"tomli>=2", # for mypy (Python<=3.10)
|
||||
@@ -224,9 +227,6 @@ enable_error_code = [
|
||||
"ignore-without-code",
|
||||
"unused-awaitable",
|
||||
]
|
||||
disable_error_code = [
|
||||
"import-untyped",
|
||||
]
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = [
|
||||
@@ -274,6 +274,14 @@ module = [
|
||||
]
|
||||
disallow_any_generics = false
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = [
|
||||
"defusedxml.ElementTree",
|
||||
"imagesize",
|
||||
"snowballstemmer",
|
||||
]
|
||||
ignore_missing_imports = true
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
minversion = "6.0"
|
||||
addopts = [
|
||||
|
||||
@@ -27,8 +27,9 @@ if TYPE_CHECKING:
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
PILLOW_AVAILABLE = True
|
||||
except ImportError:
|
||||
Image = None
|
||||
PILLOW_AVAILABLE = False
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -440,7 +441,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
"""
|
||||
if self.images:
|
||||
if self.config.epub_fix_images or self.config.epub_max_image_width:
|
||||
if not Image:
|
||||
if not PILLOW_AVAILABLE:
|
||||
logger.warning(__('Pillow not found - copying image files'))
|
||||
super().copy_image_files()
|
||||
else:
|
||||
|
||||
@@ -86,8 +86,8 @@ _LATEX_ADD_STYLES = r"""
|
||||
class PygmentsBridge:
|
||||
# Set these attributes if you want to have different Pygments formatters
|
||||
# than the default ones.
|
||||
html_formatter = HtmlFormatter
|
||||
latex_formatter = LatexFormatter
|
||||
html_formatter = HtmlFormatter[str]
|
||||
latex_formatter = LatexFormatter[str]
|
||||
|
||||
def __init__(
|
||||
self, dest: str = 'html', stylename: str = 'sphinx', latex_engine: str | None = None
|
||||
@@ -98,7 +98,7 @@ class PygmentsBridge:
|
||||
style = self.get_style(stylename)
|
||||
self.formatter_args: dict[str, Any] = {'style': style}
|
||||
if dest == 'html':
|
||||
self.formatter = self.html_formatter
|
||||
self.formatter: type[Formatter[str]] = self.html_formatter
|
||||
else:
|
||||
self.formatter = self.latex_formatter
|
||||
self.formatter_args['commandprefix'] = 'PYG'
|
||||
|
||||
@@ -28,12 +28,12 @@ class SphinxStyle(Style):
|
||||
background_color = '#eeffcc'
|
||||
default_style = ''
|
||||
|
||||
styles = FriendlyStyle.styles
|
||||
styles.update({
|
||||
styles = {
|
||||
**FriendlyStyle.styles,
|
||||
Generic.Output: '#333',
|
||||
Comment: 'italic #408090',
|
||||
Number: '#208050',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
class PyramidStyle(Style):
|
||||
|
||||
@@ -41,8 +41,9 @@ if TYPE_CHECKING:
|
||||
try:
|
||||
# check if colorama is installed to support color on Windows
|
||||
import colorama
|
||||
COLORAMA_AVAILABLE = True
|
||||
except ImportError:
|
||||
colorama = None
|
||||
COLORAMA_AVAILABLE = False
|
||||
|
||||
_CSI: Final[str] = re.escape('\x1b[') # 'ESC [': Control Sequence Introducer
|
||||
|
||||
@@ -92,7 +93,7 @@ def term_width_line(text: str) -> str:
|
||||
def color_terminal() -> bool:
|
||||
if 'NO_COLOR' in os.environ:
|
||||
return False
|
||||
if sys.platform == 'win32' and colorama is not None:
|
||||
if sys.platform == 'win32' and COLORAMA_AVAILABLE:
|
||||
colorama.just_fix_windows_console()
|
||||
return True
|
||||
if 'FORCE_COLOR' in os.environ:
|
||||
@@ -108,7 +109,7 @@ def color_terminal() -> bool:
|
||||
|
||||
|
||||
def nocolor() -> None:
|
||||
if sys.platform == 'win32' and colorama is not None:
|
||||
if sys.platform == 'win32' and COLORAMA_AVAILABLE:
|
||||
colorama.deinit()
|
||||
codes.clear()
|
||||
|
||||
|
||||
@@ -13,8 +13,9 @@ if TYPE_CHECKING:
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
PILLOW_AVAILABLE = True
|
||||
except ImportError:
|
||||
Image = None
|
||||
PILLOW_AVAILABLE = False
|
||||
|
||||
mime_suffixes = {
|
||||
'.gif': 'image/gif',
|
||||
@@ -43,7 +44,7 @@ def get_image_size(filename: str) -> tuple[int, int] | None:
|
||||
elif isinstance(size[0], float) or isinstance(size[1], float):
|
||||
size = (int(size[0]), int(size[1]))
|
||||
|
||||
if size is None and Image: # fallback to Pillow
|
||||
if size is None and PILLOW_AVAILABLE: # fallback to Pillow
|
||||
with Image.open(filename) as im:
|
||||
size = im.size
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class MyLexer(RegexLexer):
|
||||
}
|
||||
|
||||
|
||||
class MyFormatter(HtmlFormatter):
|
||||
class MyFormatter(HtmlFormatter[str]):
|
||||
def format(self, tokensource, outfile):
|
||||
for tok in tokensource:
|
||||
outfile.write(tok[1])
|
||||
|
||||
Reference in New Issue
Block a user