Skip to content

Commit 2c1dd0c

Browse files
committed
Merge branch 'main' into stubs-pygments-complete-misc
2 parents 8631672 + 4495b83 commit 2c1dd0c

File tree

20 files changed

+177
-159
lines changed

20 files changed

+177
-159
lines changed

stdlib/_operator.pyi

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import sys
2-
from _typeshed import SupportsGetItem, SupportsMul, SupportsRMul
2+
from _typeshed import (
3+
SupportsAdd,
4+
SupportsGetItem,
5+
SupportsMod,
6+
SupportsMul,
7+
SupportsRAdd,
8+
SupportsRMod,
9+
SupportsRMul,
10+
SupportsRSub,
11+
SupportsSub,
12+
)
313
from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence
414
from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller
515
from typing import Any, AnyStr, Protocol, SupportsAbs, SupportsIndex, TypeVar, overload, type_check_only
@@ -59,14 +69,20 @@ def truth(a: object, /) -> bool: ...
5969
def is_(a: object, b: object, /) -> bool: ...
6070
def is_not(a: object, b: object, /) -> bool: ...
6171
def abs(a: SupportsAbs[_T], /) -> _T: ...
62-
def add(a, b, /): ...
72+
@overload
73+
def add(a: SupportsAdd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ...
74+
@overload
75+
def add(a: _T_contra, b: SupportsRAdd[_T_contra, _T_co], /) -> _T_co: ...
6376
def and_(a, b, /): ...
6477
def floordiv(a, b, /): ...
6578
def index(a: SupportsIndex, /) -> int: ...
6679
def inv(a: _SupportsInversion[_T_co], /) -> _T_co: ...
6780
def invert(a: _SupportsInversion[_T_co], /) -> _T_co: ...
6881
def lshift(a, b, /): ...
69-
def mod(a, b, /): ...
82+
@overload
83+
def mod(a: SupportsMod[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ...
84+
@overload
85+
def mod(a: _T_contra, b: SupportsRMod[_T_contra, _T_co], /) -> _T_co: ...
7086
@overload
7187
def mul(a: SupportsMul[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ...
7288
@overload
@@ -77,7 +93,10 @@ def or_(a, b, /): ...
7793
def pos(a: _SupportsPos[_T_co], /) -> _T_co: ...
7894
def pow(a, b, /): ...
7995
def rshift(a, b, /): ...
80-
def sub(a, b, /): ...
96+
@overload
97+
def sub(a: SupportsSub[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ...
98+
@overload
99+
def sub(a: _T_contra, b: SupportsRSub[_T_contra, _T_co], /) -> _T_co: ...
81100
def truediv(a, b, /): ...
82101
def xor(a, b, /): ...
83102
def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ...

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)