Skip to content

Commit c94d18a

Browse files
authored
Merge branch 'main' into main
2 parents fd6c0e3 + 4abe0b8 commit c94d18a

File tree

19 files changed

+156
-155
lines changed

19 files changed

+156
-155
lines changed

stdlib/_codecs.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def ascii_decode(data: ReadableBuffer, errors: str | None = None, /) -> tuple[st
7777
def ascii_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
7878
def charmap_decode(data: ReadableBuffer, errors: str | None = None, mapping: _CharMap | None = None, /) -> tuple[str, int]: ...
7979
def charmap_encode(str: str, errors: str | None = None, mapping: _CharMap | None = None, /) -> tuple[bytes, int]: ...
80-
def escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
80+
81+
# Docs say this accepts a bytes-like object, but in practice it also accepts str.
82+
def escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[bytes, int]: ...
8183
def escape_encode(data: bytes, errors: str | None = None, /) -> tuple[bytes, int]: ...
8284
def latin_1_decode(data: ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
8385
def latin_1_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...

stdlib/_typeshed/__init__.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ class SupportsMul(Protocol[_T_contra, _T_co]):
126126
class SupportsRMul(Protocol[_T_contra, _T_co]):
127127
def __rmul__(self, x: _T_contra, /) -> _T_co: ...
128128

129+
class SupportsMod(Protocol[_T_contra, _T_co]):
130+
def __mod__(self, other: _T_contra, /) -> _T_co: ...
131+
132+
class SupportsRMod(Protocol[_T_contra, _T_co]):
133+
def __rmod__(self, other: _T_contra, /) -> _T_co: ...
134+
129135
class SupportsDivMod(Protocol[_T_contra, _T_co]):
130136
def __divmod__(self, other: _T_contra, /) -> _T_co: ...
131137

stubs/Pygments/@tests/stubtest_allowlist.txt

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,21 @@
22
pygments.lexer.LexerMeta.__new__
33
pygments.style.StyleMeta.__new__
44

5-
# Defined in lexer classes, intended to be used as static method, but doesn't use @staticmethod
6-
pygments.lexer.Lexer(Meta)?.analyse_text
7-
85
# Inheriting from tuple is weird
96
pygments.token._TokenType.__init__
107

118
# Cannot import in stubtest (SystemExit: 2)
129
pygments.__main__
1310

14-
# Class attributes that are typed in the metaclass instead. See comment in stubs.
11+
# Class attributes that are set to None in the base class, but are
12+
# always overridden with a non-None value in subclasses.
1513
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
2114
pygments.lexer.Lexer.url
2215
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
16+
17+
# Class attributes that are set to None in the base class, but are
18+
# always overridden with a non-None value in subclasses.
19+
pygments.formatter.Formatter.name
3320

3421
# Individual lexers and styles submodules are not stubbed at this time.
3522
pygments\.lexers\.(?!get_|find_|load_|guess_).*
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing_extensions import assert_type
2+
3+
from pygments.style import Style, _StyleDict
4+
from pygments.token import _TokenType
5+
6+
7+
def test_style_class_iterable(style_class: type[Style]) -> None:
8+
for t, d in style_class:
9+
assert_type(t, _TokenType)
10+
assert_type(d, _StyleDict)
Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
11
import types
2-
from _typeshed import Incomplete
3-
from typing import Any, Generic, TypeVar, overload
2+
from _typeshed import SupportsWrite
3+
from collections.abc import Iterable, Sequence
4+
from typing import Any, ClassVar, Generic, TypeVar, overload
5+
6+
from pygments.style import Style
7+
from pygments.token import _TokenType
48

59
_T = TypeVar("_T", str, bytes)
610

711
__all__ = ["Formatter"]
812

913
class Formatter(Generic[_T]):
10-
name: Incomplete
11-
aliases: Incomplete
12-
filenames: Incomplete
13-
unicodeoutput: bool
14-
style: Incomplete
15-
full: Incomplete
16-
title: Incomplete
17-
encoding: Incomplete
18-
options: Incomplete
14+
name: ClassVar[str] # Set to None, but always overridden with a non-None value in subclasses.
15+
aliases: ClassVar[Sequence[str]] # Not intended to be mutable
16+
filenames: ClassVar[Sequence[str]] # Not intended to be mutable
17+
unicodeoutput: ClassVar[bool]
18+
style: type[Style]
19+
full: bool
20+
title: str
21+
encoding: str | None
22+
options: dict[str, Any] # arbitrary values used by subclasses
1923
@overload
20-
def __init__(self: Formatter[str], *, encoding: None = None, outencoding: None = None, **options) -> None: ...
24+
def __init__(
25+
self: Formatter[str],
26+
*,
27+
style: type[Style] | str = "default",
28+
full: bool = False,
29+
title: str = "",
30+
encoding: None = None,
31+
outencoding: None = None,
32+
**options: Any, # arbitrary values used by subclasses
33+
) -> None: ...
2134
@overload
22-
def __init__(self: Formatter[bytes], *, encoding: str, outencoding: None = None, **options) -> None: ...
35+
def __init__(
36+
self: Formatter[bytes],
37+
*,
38+
style: type[Style] | str = "default",
39+
full: bool = False,
40+
title: str = "",
41+
encoding: str,
42+
outencoding: None = None,
43+
**options: Any, # arbitrary values used by subclasses
44+
) -> None: ...
2345
@overload
24-
def __init__(self: Formatter[bytes], *, encoding: None = None, outencoding: str, **options) -> None: ...
46+
def __init__(
47+
self: Formatter[bytes],
48+
*,
49+
style: type[Style] | str = "default",
50+
full: bool = False,
51+
title: str = "",
52+
encoding: None = None,
53+
outencoding: str,
54+
**options: Any, # arbitrary values used by subclasses
55+
) -> None: ...
2556
def __class_getitem__(cls, name: Any) -> types.GenericAlias: ...
26-
def get_style_defs(self, arg: str = ""): ...
27-
def format(self, tokensource, outfile): ...
57+
def get_style_defs(self, arg: str = "") -> str: ...
58+
def format(self, tokensource: Iterable[tuple[_TokenType, str]], outfile: SupportsWrite[_T]) -> None: ...
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import SupportsWrite
2+
from collections.abc import Iterable
23
from typing import TypeVar
34

45
from pygments.formatter import Formatter
6+
from pygments.token import _TokenType
57

68
_T = TypeVar("_T", str, bytes)
79

810
__all__ = ["BBCodeFormatter"]
911

1012
class BBCodeFormatter(Formatter[_T]):
11-
name: str
12-
aliases: Incomplete
13-
filenames: Incomplete
14-
styles: Incomplete
15-
def format_unencoded(self, tokensource, outfile) -> None: ...
13+
styles: dict[_TokenType, tuple[str, str]]
14+
def format_unencoded(self, tokensource: Iterable[tuple[_TokenType, str]], outfile: SupportsWrite[str]) -> None: ...

stubs/Pygments/pygments/formatters/html.pyi

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import Incomplete, SupportsWrite
2+
from collections.abc import Iterable
23
from typing import TypeVar
34

45
from pygments.formatter import Formatter
6+
from pygments.token import _TokenType
57

68
_T = TypeVar("_T", str, bytes)
79

810
__all__ = ["HtmlFormatter"]
911

1012
class HtmlFormatter(Formatter[_T]):
11-
name: str
12-
aliases: Incomplete
13-
filenames: Incomplete
1413
title: Incomplete
1514
nowrap: Incomplete
1615
noclasses: Incomplete
@@ -41,4 +40,4 @@ class HtmlFormatter(Formatter[_T]):
4140
def get_linenos_style_defs(self): ...
4241
def get_css_prefix(self, arg): ...
4342
def wrap(self, source): ...
44-
def format_unencoded(self, tokensource, outfile) -> None: ...
43+
def format_unencoded(self, tokensource: Iterable[tuple[_TokenType, str]], outfile: SupportsWrite[str]) -> None: ...

stubs/Pygments/pygments/formatters/img.pyi

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from _typeshed import Incomplete
2-
from typing import TypeVar
1+
from _typeshed import Incomplete, SupportsWrite
2+
from collections.abc import Iterable
3+
from typing_extensions import Never
34

45
from pygments.formatter import Formatter
5-
6-
_T = TypeVar("_T", str, bytes)
6+
from pygments.token import _TokenType
77

88
__all__ = ["ImageFormatter", "GifImageFormatter", "JpgImageFormatter", "BmpImageFormatter"]
99

@@ -22,11 +22,7 @@ class FontManager:
2222
def get_font(self, bold, oblique): ...
2323
def get_style(self, style): ...
2424

25-
class ImageFormatter(Formatter[_T]):
26-
name: str
27-
aliases: Incomplete
28-
filenames: Incomplete
29-
unicodeoutput: bool
25+
class ImageFormatter(Formatter[bytes]):
3026
default_image_format: str
3127
encoding: str
3228
styles: Incomplete
@@ -49,23 +45,14 @@ class ImageFormatter(Formatter[_T]):
4945
hl_lines: Incomplete
5046
hl_color: Incomplete
5147
drawables: Incomplete
52-
def get_style_defs(self, arg: str = "") -> None: ...
53-
def format(self, tokensource, outfile) -> None: ...
48+
def get_style_defs(self, arg: str = "") -> Never: ...
49+
def format(self, tokensource: Iterable[tuple[_TokenType, str]], outfile: SupportsWrite[bytes]) -> None: ...
5450

55-
class GifImageFormatter(ImageFormatter[_T]):
56-
name: str
57-
aliases: Incomplete
58-
filenames: Incomplete
51+
class GifImageFormatter(ImageFormatter):
5952
default_image_format: str
6053

61-
class JpgImageFormatter(ImageFormatter[_T]):
62-
name: str
63-
aliases: Incomplete
64-
filenames: Incomplete
54+
class JpgImageFormatter(ImageFormatter):
6555
default_image_format: str
6656

67-
class BmpImageFormatter(ImageFormatter[_T]):
68-
name: str
69-
aliases: Incomplete
70-
filenames: Incomplete
57+
class BmpImageFormatter(ImageFormatter):
7158
default_image_format: str
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import Incomplete, SupportsWrite
2+
from collections.abc import Iterable
23
from typing import TypeVar
34

45
from pygments.formatter import Formatter
6+
from pygments.token import _TokenType
57

68
_T = TypeVar("_T", str, bytes)
79

810
__all__ = ["IRCFormatter"]
911

1012
class IRCFormatter(Formatter[_T]):
11-
name: str
12-
aliases: Incomplete
13-
filenames: Incomplete
1413
darkbg: Incomplete
1514
colorscheme: Incomplete
1615
linenos: Incomplete
17-
def format_unencoded(self, tokensource, outfile) -> None: ...
16+
def format_unencoded(self, tokensource: Iterable[tuple[_TokenType, str]], outfile: SupportsWrite[str]) -> None: ...

stubs/Pygments/pygments/formatters/latex.pyi

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import Incomplete, SupportsWrite
2+
from collections.abc import Iterable
23
from typing import TypeVar
34

45
from pygments.formatter import Formatter
56
from pygments.lexer import Lexer
7+
from pygments.token import _TokenType
68

79
_T = TypeVar("_T", str, bytes)
810

911
__all__ = ["LatexFormatter"]
1012

1113
class LatexFormatter(Formatter[_T]):
12-
name: str
13-
aliases: Incomplete
14-
filenames: Incomplete
1514
docclass: Incomplete
1615
preamble: Incomplete
1716
linenos: Incomplete
@@ -27,7 +26,7 @@ class LatexFormatter(Formatter[_T]):
2726
right: Incomplete
2827
envname: Incomplete
2928
def get_style_defs(self, arg: str = ""): ...
30-
def format_unencoded(self, tokensource, outfile) -> None: ...
29+
def format_unencoded(self, tokensource: Iterable[tuple[_TokenType, str]], outfile: SupportsWrite[str]) -> None: ...
3130

3231
class LatexEmbeddedLexer(Lexer):
3332
left: Incomplete

0 commit comments

Comments
 (0)