Skip to content

Commit 16017c1

Browse files
Address review comments
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
1 parent a6bae61 commit 16017c1

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

stubs/Pygments/pygments/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from _typeshed import SupportsWrite
2-
from collections.abc import Iterator
2+
from collections.abc import Iterable, Iterator
33
from typing import Final, TypeVar, overload
44

55
from pygments.formatter import Formatter
@@ -14,9 +14,9 @@ __all__ = ["lex", "format", "highlight"]
1414

1515
def lex(code: str, lexer: Lexer) -> Iterator[tuple[_TokenType, str]]: ...
1616
@overload
17-
def format(tokens: Iterator[tuple[_TokenType, str]], formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ...
17+
def format(tokens: Iterable[tuple[_TokenType, str]], formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ...
1818
@overload
19-
def format(tokens: Iterator[tuple[_TokenType, str]], formatter: Formatter[_T], outfile: None = None) -> _T: ...
19+
def format(tokens: Iterable[tuple[_TokenType, str]], formatter: Formatter[_T], outfile: None = None) -> _T: ...
2020
@overload
2121
def highlight(code: str, lexer: Lexer, formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ...
2222
@overload

stubs/Pygments/pygments/util.pyi

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from collections.abc import Callable, Container, Hashable, Iterable, Mapping
1+
from collections.abc import Callable, Container, Hashable, Iterable
22
from io import TextIOWrapper
33
from re import Pattern
4-
from typing import Any, Final, TextIO, TypeVar
4+
from typing import Any, Final, Protocol, TypeVar, type_check_only
55

66
_T = TypeVar("_T")
77
_H = TypeVar("_H", bound=Hashable)
@@ -14,16 +14,22 @@ xml_decl_re: Final[Pattern[str]]
1414
class ClassNotFound(ValueError): ...
1515
class OptionError(Exception): ...
1616

17+
@type_check_only
18+
class _SupportsGetStrWithDefault(Protocol):
19+
def get(self, item: str, default: Any, /) -> Any: ...
20+
1721
# 'options' contains the **kwargs of an arbitrary function.
1822
def get_choice_opt(
19-
options: Mapping[str, Any], optname: str, allowed: Container[_T], default: _T | None = None, normcase: bool = False
23+
options: _SupportsGetStrWithDefault, optname: str, allowed: Container[_T], default: _T | None = None, normcase: bool = False
2024
) -> _T: ...
21-
def get_bool_opt(options: Mapping[str, Any], optname: str, default: bool | None = None) -> bool: ...
22-
def get_int_opt(options: Mapping[str, Any], optname: str, default: int | None = None) -> int: ...
25+
def get_bool_opt(options: _SupportsGetStrWithDefault, optname: str, default: bool | None = None) -> bool: ...
26+
def get_int_opt(options: _SupportsGetStrWithDefault, optname: str, default: int | None = None) -> int: ...
2327

2428
# Return type and type of 'default' depend on the signature of the function whose **kwargs
2529
# are being processed.
26-
def get_list_opt(options: Mapping[str, Any], optname: str, default: list[Any] | tuple[Any, ...] | None = None) -> list[Any]: ...
30+
def get_list_opt(
31+
options: _SupportsGetStrWithDefault, optname: str, default: list[Any] | tuple[Any, ...] | None = None
32+
) -> list[Any]: ...
2733
def docstring_headline(obj: object) -> str: ...
2834
def make_analysator(f: Callable[[str], float]) -> Callable[[str], float]: ...
2935
def shebang_matches(text: str, regex: str) -> bool: ...
@@ -38,8 +44,10 @@ class Future:
3844
def get(self) -> None: ...
3945

4046
def guess_decode(text: bytes) -> tuple[str, str]: ...
41-
def guess_decode_from_terminal(text: bytes, term: TextIO) -> tuple[str, str]: ...
42-
def terminal_encoding(term: TextIO) -> str: ...
47+
48+
# If 'term' has an 'encoding' attribute, it should be a str. Otherwise any object is accepted.
49+
def guess_decode_from_terminal(text: bytes, term: Any) -> tuple[str, str]: ...
50+
def terminal_encoding(term: Any) -> str: ...
4351

4452
class UnclosingTextIOWrapper(TextIOWrapper):
4553
def close(self) -> None: ...

0 commit comments

Comments
 (0)