Skip to content

Commit 97d1089

Browse files
[Pygments] Check for missing stubs outside omitted subpackages (#15606)
1 parent 174c932 commit 97d1089

File tree

19 files changed

+127
-7
lines changed

19 files changed

+127
-7
lines changed

stubs/Pygments/@tests/stubtest_allowlist.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,34 @@ pygments.lexer.LexerMeta.__new__
33
pygments.style.StyleMeta.__new__
44

55
# Defined in lexer classes, intended to be used as static method, but doesn't use @staticmethod
6-
pygments.lexer.LexerMeta.analyse_text
6+
pygments.lexer.Lexer(Meta)?.analyse_text
77

88
# Inheriting from tuple is weird
99
pygments.token._TokenType.__init__
10+
11+
# Cannot import in stubtest (SystemExit: 2)
12+
pygments.__main__
13+
14+
# Class attributes that are typed in the metaclass instead. See comment in stubs.
15+
pygments.lexer.Lexer.name
16+
pygments.lexer.Lexer.aliases
17+
pygments.lexer.Lexer.filenames
18+
pygments.lexer.Lexer.alias_filenames
19+
pygments.lexer.Lexer.mimetypes
20+
pygments.lexer.Lexer.priority
21+
pygments.lexer.Lexer.url
22+
pygments.lexer.Lexer.version_added
23+
pygments.style.Style.background_color
24+
pygments.style.Style.highlight_color
25+
pygments.style.Style.line_number_color
26+
pygments.style.Style.line_number_background_color
27+
pygments.style.Style.line_number_special_color
28+
pygments.style.Style.line_number_special_background_color
29+
pygments.style.Style.styles
30+
pygments.style.Style.name
31+
pygments.style.Style.aliases
32+
pygments.style.Style.web_style_gallery_exclude
33+
34+
# Individual lexers and styles submodules are not stubbed at this time.
35+
pygments\.lexers\.(?!get_|find_|load_|guess_).*
36+
pygments\.styles\.(?!get_).*

stubs/Pygments/METADATA.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ partial_stub = true
55

66
[tool.stubtest]
77
stubtest_dependencies = ["sphinx"]
8-
ignore_missing_stub = true

stubs/Pygments/pygments/formatter.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import types
12
from _typeshed import Incomplete
2-
from typing import Generic, TypeVar, overload
3+
from typing import Any, Generic, TypeVar, overload
34

45
_T = TypeVar("_T", str, bytes)
56

7+
__all__ = ["Formatter"]
8+
69
class Formatter(Generic[_T]):
710
name: Incomplete
811
aliases: Incomplete
@@ -19,5 +22,6 @@ class Formatter(Generic[_T]):
1922
def __init__(self: Formatter[bytes], *, encoding: str, outencoding: None = None, **options) -> None: ...
2023
@overload
2124
def __init__(self: Formatter[bytes], *, encoding: None = None, outencoding: str, **options) -> None: ...
25+
def __class_getitem__(cls, name: Any) -> types.GenericAlias: ...
2226
def get_style_defs(self, arg: str = ""): ...
2327
def format(self, tokensource, outfile): ...

stubs/Pygments/pygments/formatters/__init__.pyi

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from collections.abc import Generator
33

44
from ..formatter import Formatter
55
from .bbcode import BBCodeFormatter as BBCodeFormatter
6+
from .groff import GroffFormatter as GroffFormatter
67
from .html import HtmlFormatter as HtmlFormatter
78
from .img import (
89
BmpImageFormatter as BmpImageFormatter,
@@ -19,6 +20,31 @@ from .svg import SvgFormatter as SvgFormatter
1920
from .terminal import TerminalFormatter as TerminalFormatter
2021
from .terminal256 import Terminal256Formatter as Terminal256Formatter, TerminalTrueColorFormatter as TerminalTrueColorFormatter
2122

23+
__all__ = [
24+
"get_formatter_by_name",
25+
"get_formatter_for_filename",
26+
"get_all_formatters",
27+
"load_formatter_from_file",
28+
"BBCodeFormatter",
29+
"BmpImageFormatter",
30+
"GifImageFormatter",
31+
"GroffFormatter",
32+
"HtmlFormatter",
33+
"IRCFormatter",
34+
"ImageFormatter",
35+
"JpgImageFormatter",
36+
"LatexFormatter",
37+
"NullFormatter",
38+
"PangoMarkupFormatter",
39+
"RawTokenFormatter",
40+
"RtfFormatter",
41+
"SvgFormatter",
42+
"Terminal256Formatter",
43+
"TerminalFormatter",
44+
"TerminalTrueColorFormatter",
45+
"TestcaseFormatter",
46+
]
47+
2248
def get_all_formatters() -> Generator[type[Formatter[Incomplete]]]: ...
2349
def get_formatter_by_name(_alias, **options): ...
2450
def load_formatter_from_file(filename, formattername: str = "CustomFormatter", **options): ...

stubs/Pygments/pygments/formatters/bbcode.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ from pygments.formatter import Formatter
55

66
_T = TypeVar("_T", str, bytes)
77

8+
__all__ = ["BBCodeFormatter"]
9+
810
class BBCodeFormatter(Formatter[_T]):
911
name: str
1012
aliases: Incomplete
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from _typeshed import SupportsWrite
2+
from collections.abc import Iterable
3+
from typing import TypeVar
4+
5+
from pygments.formatter import Formatter
6+
from pygments.token import _TokenType
7+
8+
__all__ = ["GroffFormatter"]
9+
10+
_T = TypeVar("_T", str, bytes)
11+
12+
class GroffFormatter(Formatter[_T]):
13+
monospaced: bool
14+
linenos: bool
15+
wrap: int
16+
styles: dict[_TokenType, tuple[str, str]]
17+
def __init__(self, **options) -> None: ...
18+
def format_unencoded(self, tokensource: Iterable[tuple[_TokenType, str]], outfile: SupportsWrite[str]) -> None: ...

stubs/Pygments/pygments/formatters/html.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ from pygments.formatter import Formatter
55

66
_T = TypeVar("_T", str, bytes)
77

8+
__all__ = ["HtmlFormatter"]
9+
810
class HtmlFormatter(Formatter[_T]):
911
name: str
1012
aliases: Incomplete

stubs/Pygments/pygments/formatters/img.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ from pygments.formatter import Formatter
55

66
_T = TypeVar("_T", str, bytes)
77

8+
__all__ = ["ImageFormatter", "GifImageFormatter", "JpgImageFormatter", "BmpImageFormatter"]
9+
810
class PilNotAvailable(ImportError): ...
911
class FontNotFound(Exception): ...
1012

stubs/Pygments/pygments/formatters/irc.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ from pygments.formatter import Formatter
55

66
_T = TypeVar("_T", str, bytes)
77

8+
__all__ = ["IRCFormatter"]
9+
810
class IRCFormatter(Formatter[_T]):
911
name: str
1012
aliases: Incomplete

stubs/Pygments/pygments/formatters/latex.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ from pygments.lexer import Lexer
66

77
_T = TypeVar("_T", str, bytes)
88

9+
__all__ = ["LatexFormatter"]
10+
911
class LatexFormatter(Formatter[_T]):
1012
name: str
1113
aliases: Incomplete

0 commit comments

Comments
 (0)