Skip to content

Commit 64d15ca

Browse files
committed
[Pygments] Complete stubs for various modules
1 parent 97d1089 commit 64d15ca

File tree

12 files changed

+160
-108
lines changed

12 files changed

+160
-108
lines changed
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
from _typeshed import SupportsWrite
22
from collections.abc import Iterator
3-
from typing import TypeVar, overload
3+
from typing import Final, TypeVar, overload
44

55
from pygments.formatter import Formatter
66
from pygments.lexer import Lexer
77
from pygments.token import _TokenType
88

99
_T = TypeVar("_T", str, bytes)
1010

11-
__version__: str
11+
__version__: Final[str]
12+
__docformat__: Final = "restructuredtext"
1213
__all__ = ["lex", "format", "highlight"]
1314

1415
def lex(code: str, lexer: Lexer) -> Iterator[tuple[_TokenType, str]]: ...
1516
@overload
16-
def format(tokens, formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ...
17+
def format(tokens: Iterator[tuple[_TokenType, str]], formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ...
1718
@overload
18-
def format(tokens, formatter: Formatter[_T], outfile: None = None) -> _T: ...
19+
def format(tokens: Iterator[tuple[_TokenType, str]], formatter: Formatter[_T], outfile: None = None) -> _T: ...
1920
@overload
20-
def highlight(code, lexer, formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ...
21+
def highlight(code: str, lexer: Lexer, formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ...
2122
@overload
22-
def highlight(code, lexer, formatter: Formatter[_T], outfile: None = None) -> _T: ...
23+
def highlight(code: str, lexer: Lexer, formatter: Formatter[_T], outfile: None = None) -> _T: ...
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import argparse
2+
from collections.abc import Sequence
23

3-
def main_inner(parser, argns): ...
4+
def main_inner(parser: argparse.ArgumentParser, argns: argparse.Namespace) -> int: ...
45

56
class HelpFormatter(argparse.HelpFormatter):
6-
def __init__(self, prog, indent_increment: int = 2, max_help_position: int = 16, width=None) -> None: ...
7+
def __init__(self, prog: str, indent_increment: int = 2, max_help_position: int = 16, width: int | None = None) -> None: ...
78

8-
def main(args=...): ...
9+
def main(args: Sequence[str] | None = ...) -> int: ...
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from _typeshed import Incomplete
1+
from typing import Final
22

3-
esc: str
4-
codes: Incomplete
5-
dark_colors: Incomplete
6-
light_colors: Incomplete
3+
esc: Final = "\x1b["
4+
codes: Final[dict[str, str]]
5+
dark_colors: Final[list[str]]
6+
light_colors: Final[list[str]]
77

8-
def reset_color(): ...
9-
def colorize(color_key, text): ...
10-
def ansiformat(attr, text): ...
8+
def reset_color() -> str: ...
9+
def colorize(color_key: str, text: str) -> str: ...
10+
def ansiformat(attr: str, text: str) -> str: ...
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__all__ = ["get_filetype_from_buffer"]
22

3-
def get_filetype_from_buffer(buf, max_lines: int = 5): ...
3+
def get_filetype_from_buffer(buf: str, max_lines: int = 5) -> str | None: ...

stubs/Pygments/pygments/plugin.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import sys
22
from _typeshed import Incomplete
33
from collections.abc import Generator
4+
from typing import Final
45

56
from pygments.filter import Filter
67
from pygments.formatter import Formatter
78
from pygments.lexer import Lexer
89
from pygments.style import Style
910

10-
LEXER_ENTRY_POINT: str
11-
FORMATTER_ENTRY_POINT: str
12-
STYLE_ENTRY_POINT: str
13-
FILTER_ENTRY_POINT: str
11+
LEXER_ENTRY_POINT: Final = "pygments.lexers"
12+
FORMATTER_ENTRY_POINT: Final = "pygments.formatters"
13+
STYLE_ENTRY_POINT: Final = "pygments.styles"
14+
FILTER_ENTRY_POINT: Final = "pygments.filters"
1415

1516
if sys.version_info >= (3, 10):
1617
from importlib.metadata import EntryPoints
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from _typeshed import Incomplete
2-
from collections.abc import Iterable
1+
import re
2+
from collections.abc import Iterable, Sequence
3+
from operator import itemgetter
4+
from typing import Final
35

4-
CS_ESCAPE: Incomplete
5-
FIRST_ELEMENT: Incomplete
6+
CS_ESCAPE: Final[re.Pattern[str]]
7+
FIRST_ELEMENT: Final[itemgetter[int]]
68

79
def commonprefix(m: Iterable[str]) -> str: ...
8-
def make_charset(letters): ...
9-
def regex_opt_inner(strings, open_paren): ...
10-
def regex_opt(strings, prefix: str = "", suffix: str = ""): ...
10+
def make_charset(letters: Iterable[str]) -> str: ...
11+
def regex_opt_inner(strings: Sequence[str], open_paren: str) -> str: ...
12+
def regex_opt(strings: Iterable[str], prefix: str = "", suffix: str = "") -> str: ...
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
from _typeshed import Incomplete
1+
from re import Match, Pattern, RegexFlag
22

33
class EndOfText(RuntimeError): ...
44

55
class Scanner:
6-
data: Incomplete
7-
data_length: Incomplete
6+
data: str
7+
data_length: int
88
start_pos: int
99
pos: int
10-
flags: Incomplete
11-
last: Incomplete
12-
match: Incomplete
13-
def __init__(self, text, flags: int = 0) -> None: ...
10+
flags: int | RegexFlag
11+
last: str | None
12+
match: str | None
13+
def __init__(self, text: str, flags: int | RegexFlag = 0) -> None: ...
1414
@property
15-
def eos(self): ...
16-
def check(self, pattern): ...
17-
def test(self, pattern): ...
18-
def scan(self, pattern): ...
15+
def eos(self) -> bool: ...
16+
def check(self, pattern: str | Pattern[str]) -> Match[str] | bool: ...
17+
def test(self, pattern: str | Pattern[str]) -> bool: ...
18+
def scan(self, pattern: str | Pattern[str]) -> bool: ...
1919
def get_char(self) -> None: ...
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from typing import Any, Final
2+
13
from docutils.parsers.rst import Directive
24

3-
MODULEDOC: str
4-
LEXERDOC: str
5-
FMTERDOC: str
6-
FILTERDOC: str
5+
MODULEDOC: Final[str]
6+
LEXERDOC: Final[str]
7+
FMTERDOC: Final[str]
8+
FILTERDOC: Final[str]
79

810
class PygmentsDoc(Directive):
911
filenames: set[str]
@@ -12,4 +14,4 @@ class PygmentsDoc(Directive):
1214
def document_formatters(self) -> str: ...
1315
def document_filters(self) -> str: ...
1416

15-
def setup(app) -> None: ...
17+
def setup(app: Any) -> None: ... # Actual type of 'app' is sphinx.application.Sphinx

stubs/Pygments/pygments/style.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from _typeshed import Self
12
from collections.abc import Iterator, Mapping, Set as AbstractSet
2-
from typing import TypedDict, type_check_only
3+
from typing import Any, TypedDict, type_check_only
34

45
from pygments.token import _TokenType
56

@@ -20,7 +21,7 @@ class _StyleDict(TypedDict):
2021
bgansicolor: str | None
2122

2223
class StyleMeta(type):
23-
def __new__(cls, name, bases, dct): ...
24+
def __new__(cls: type[Self], name, bases: tuple[type[Any], ...], dct: dict[str, Any]) -> Self: ...
2425
def style_for_token(cls, token: _TokenType) -> _StyleDict: ...
2526
def styles_token(cls, ttype: _TokenType) -> bool: ...
2627
def list_styles(cls) -> list[tuple[_TokenType, _StyleDict]]: ...

stubs/Pygments/pygments/token.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Mapping
2-
from typing import Any
2+
from typing import Any, Final
33
from typing_extensions import Self
44

55
class _TokenType(tuple[str, ...]):
@@ -27,8 +27,8 @@ Operator: _TokenType
2727
Comment: _TokenType
2828
Generic: _TokenType
2929

30-
def is_token_subtype(ttype, other): ...
31-
def string_to_tokentype(s): ...
30+
def is_token_subtype(ttype: _TokenType, other: _TokenType) -> bool: ...
31+
def string_to_tokentype(s: str) -> _TokenType: ...
3232

3333
# dict, but shouldn't be mutated
34-
STANDARD_TYPES: Mapping[_TokenType, str]
34+
STANDARD_TYPES: Final[Mapping[_TokenType, str]]

0 commit comments

Comments
 (0)