-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[Pygments] Complete stubs for various modules #15610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brianschubert
wants to merge
7
commits into
python:main
Choose a base branch
from
brianschubert:stubs-pygments-complete-misc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c4d9c65
[Pygments] Complete stubs for various modules
brianschubert 2f63f68
Missed one
brianschubert 8631672
Fix `make_analysator` signature
brianschubert 2c1dd0c
Merge branch 'main' into stubs-pygments-complete-misc
brianschubert a6bae61
Condense allowlist from previous PRs
brianschubert 16017c1
Address review comments
brianschubert c5ed2ce
Fix `string_to_tokentype`
brianschubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,23 @@ | ||
| from _typeshed import SupportsWrite | ||
| from collections.abc import Iterator | ||
| from typing import TypeVar, overload | ||
| from collections.abc import Iterable, Iterator | ||
| from typing import Final, TypeVar, overload | ||
|
|
||
| from pygments.formatter import Formatter | ||
| from pygments.lexer import Lexer | ||
| from pygments.token import _TokenType | ||
|
|
||
| _T = TypeVar("_T", str, bytes) | ||
|
|
||
| __version__: str | ||
| __version__: Final[str] | ||
| __docformat__: Final = "restructuredtext" | ||
| __all__ = ["lex", "format", "highlight"] | ||
|
|
||
| def lex(code: str, lexer: Lexer) -> Iterator[tuple[_TokenType, str]]: ... | ||
| @overload | ||
| def format(tokens, formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ... | ||
| def format(tokens: Iterable[tuple[_TokenType, str]], formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ... | ||
| @overload | ||
| def format(tokens, formatter: Formatter[_T], outfile: None = None) -> _T: ... | ||
| def format(tokens: Iterable[tuple[_TokenType, str]], formatter: Formatter[_T], outfile: None = None) -> _T: ... | ||
| @overload | ||
| def highlight(code, lexer, formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ... | ||
| def highlight(code: str, lexer: Lexer, formatter: Formatter[_T], outfile: SupportsWrite[_T]) -> None: ... | ||
| @overload | ||
| def highlight(code, lexer, formatter: Formatter[_T], outfile: None = None) -> _T: ... | ||
| def highlight(code: str, lexer: Lexer, formatter: Formatter[_T], outfile: None = None) -> _T: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| import argparse | ||
| from collections.abc import Sequence | ||
|
|
||
| def main_inner(parser, argns): ... | ||
| def main_inner(parser: argparse.ArgumentParser, argns: argparse.Namespace) -> int: ... | ||
|
|
||
| class HelpFormatter(argparse.HelpFormatter): | ||
| def __init__(self, prog, indent_increment: int = 2, max_help_position: int = 16, width=None) -> None: ... | ||
| def __init__(self, prog: str, indent_increment: int = 2, max_help_position: int = 16, width: int | None = None) -> None: ... | ||
|
|
||
| def main(args=...): ... | ||
| def main(args: Sequence[str] | None = ...) -> int: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| from _typeshed import Incomplete | ||
| from typing import Final | ||
|
|
||
| esc: str | ||
| codes: Incomplete | ||
| dark_colors: Incomplete | ||
| light_colors: Incomplete | ||
| esc: Final = "\x1b[" | ||
| codes: Final[dict[str, str]] | ||
| dark_colors: Final[list[str]] | ||
| light_colors: Final[list[str]] | ||
|
|
||
| def reset_color(): ... | ||
| def colorize(color_key, text): ... | ||
| def ansiformat(attr, text): ... | ||
| def reset_color() -> str: ... | ||
| def colorize(color_key: str, text: str) -> str: ... | ||
| def ansiformat(attr: str, text: str) -> str: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| __all__ = ["get_filetype_from_buffer"] | ||
|
|
||
| def get_filetype_from_buffer(buf, max_lines: int = 5): ... | ||
| def get_filetype_from_buffer(buf: str, max_lines: int = 5) -> str | None: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| from _typeshed import Incomplete | ||
| from collections.abc import Iterable | ||
| import re | ||
| from collections.abc import Iterable, Sequence | ||
| from operator import itemgetter | ||
| from typing import Final | ||
|
|
||
| CS_ESCAPE: Incomplete | ||
| FIRST_ELEMENT: Incomplete | ||
| CS_ESCAPE: Final[re.Pattern[str]] | ||
| FIRST_ELEMENT: Final[itemgetter[int]] | ||
|
|
||
| def commonprefix(m: Iterable[str]) -> str: ... | ||
| def make_charset(letters): ... | ||
| def regex_opt_inner(strings, open_paren): ... | ||
| def regex_opt(strings, prefix: str = "", suffix: str = ""): ... | ||
| def make_charset(letters: Iterable[str]) -> str: ... | ||
| def regex_opt_inner(strings: Sequence[str], open_paren: str) -> str: ... | ||
| def regex_opt(strings: Iterable[str], prefix: str = "", suffix: str = "") -> str: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,19 @@ | ||
| from _typeshed import Incomplete | ||
| from re import Match, Pattern, RegexFlag | ||
|
|
||
| class EndOfText(RuntimeError): ... | ||
|
|
||
| class Scanner: | ||
| data: Incomplete | ||
| data_length: Incomplete | ||
| data: str | ||
| data_length: int | ||
| start_pos: int | ||
| pos: int | ||
| flags: Incomplete | ||
| last: Incomplete | ||
| match: Incomplete | ||
| def __init__(self, text, flags: int = 0) -> None: ... | ||
| flags: int | RegexFlag | ||
| last: str | None | ||
| match: str | None | ||
| def __init__(self, text: str, flags: int | RegexFlag = 0) -> None: ... | ||
| @property | ||
| def eos(self): ... | ||
| def check(self, pattern): ... | ||
| def test(self, pattern): ... | ||
| def scan(self, pattern): ... | ||
| def eos(self) -> bool: ... | ||
| def check(self, pattern: str | Pattern[str]) -> Match[str] | None: ... | ||
| def test(self, pattern: str | Pattern[str]) -> bool: ... | ||
| def scan(self, pattern: str | Pattern[str]) -> bool: ... | ||
| def get_char(self) -> None: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,71 @@ | ||
| from _typeshed import Incomplete | ||
| from typing import Final, Literal, TypeAlias | ||
|
|
||
| Cc: str | ||
| Cf: str | ||
| Cn: str | ||
| Co: str | ||
| Cs: str | ||
| Ll: str | ||
| Lm: str | ||
| Lo: str | ||
| Lt: str | ||
| Lu: str | ||
| Mc: str | ||
| Me: str | ||
| Mn: str | ||
| Nd: str | ||
| Nl: str | ||
| No: str | ||
| Pc: str | ||
| Pd: str | ||
| Pe: str | ||
| Pf: str | ||
| Pi: str | ||
| Po: str | ||
| Ps: str | ||
| Sc: str | ||
| Sk: str | ||
| Sm: str | ||
| So: str | ||
| Zl: str | ||
| Zp: str | ||
| Zs: str | ||
| xid_continue: str | ||
| xid_start: str | ||
| cats: Incomplete | ||
| _Cats: TypeAlias = Literal[ | ||
| "Cc", | ||
| "Cf", | ||
| "Cn", | ||
| "Co", | ||
| "Cs", | ||
| "Ll", | ||
| "Lm", | ||
| "Lo", | ||
| "Lt", | ||
| "Lu", | ||
| "Mc", | ||
| "Me", | ||
| "Mn", | ||
| "Nd", | ||
| "Nl", | ||
| "No", | ||
| "Pc", | ||
| "Pd", | ||
| "Pe", | ||
| "Pf", | ||
| "Pi", | ||
| "Po", | ||
| "Ps", | ||
| "Sc", | ||
| "Sk", | ||
| "Sm", | ||
| "So", | ||
| "Zl", | ||
| "Zp", | ||
| "Zs", | ||
| ] | ||
|
|
||
| def combine(*args): ... | ||
| def allexcept(*args): ... | ||
| Cc: Final[str] | ||
| Cf: Final[str] | ||
| Cn: Final[str] | ||
| Co: Final[str] | ||
| Cs: Final[str] | ||
| Ll: Final[str] | ||
| Lm: Final[str] | ||
| Lo: Final[str] | ||
| Lt: Final[str] | ||
| Lu: Final[str] | ||
| Mc: Final[str] | ||
| Me: Final[str] | ||
| Mn: Final[str] | ||
| Nd: Final[str] | ||
| Nl: Final[str] | ||
| No: Final[str] | ||
| Pc: Final[str] | ||
| Pd: Final[str] | ||
| Pe: Final[str] | ||
| Pf: Final[str] | ||
| Pi: Final[str] | ||
| Po: Final[str] | ||
| Ps: Final[str] | ||
| Sc: Final[str] | ||
| Sk: Final[str] | ||
| Sm: Final[str] | ||
| So: Final[str] | ||
| Zl: Final[str] | ||
| Zp: Final[str] | ||
| Zs: Final[str] | ||
| xid_continue: Final[str] | ||
| xid_start: Final[str] | ||
| cats: Final[list[_Cats]] | ||
|
|
||
| def combine(*args: _Cats) -> str: ... | ||
| def allexcept(*args: _Cats) -> str: ... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,53 @@ | ||
| from _typeshed import Incomplete | ||
| from collections.abc import Callable, Container, Hashable, Iterable | ||
| from io import TextIOWrapper | ||
| from re import Pattern | ||
| from typing import Any, Final, Protocol, TypeVar, type_check_only | ||
|
|
||
| split_path_re: Incomplete | ||
| doctype_lookup_re: Incomplete | ||
| tag_re: Incomplete | ||
| xml_decl_re: Incomplete | ||
| _T = TypeVar("_T") | ||
| _H = TypeVar("_H", bound=Hashable) | ||
|
|
||
| split_path_re: Final[Pattern[str]] | ||
| doctype_lookup_re: Final[Pattern[str]] | ||
| tag_re: Final[Pattern[str]] | ||
| xml_decl_re: Final[Pattern[str]] | ||
|
|
||
| class ClassNotFound(ValueError): ... | ||
| class OptionError(Exception): ... | ||
|
|
||
| def get_choice_opt(options, optname, allowed, default=None, normcase: bool = False): ... | ||
| def get_bool_opt(options, optname, default=None): ... | ||
| def get_int_opt(options, optname, default=None): ... | ||
| def get_list_opt(options, optname, default=None): ... | ||
| def docstring_headline(obj): ... | ||
| def make_analysator(f): ... | ||
| def shebang_matches(text, regex): ... | ||
| def doctype_matches(text, regex): ... | ||
| def html_doctype_matches(text): ... | ||
| def looks_like_xml(text): ... | ||
| def surrogatepair(c): ... | ||
| def format_lines(var_name, seq, raw: bool = False, indent_level: int = 0): ... | ||
| def duplicates_removed(it, already_seen=()): ... | ||
| @type_check_only | ||
| class _SupportsGetStrWithDefault(Protocol): | ||
| def get(self, item: str, default: Any, /) -> Any: ... | ||
|
|
||
| # 'options' contains the **kwargs of an arbitrary function. | ||
| def get_choice_opt( | ||
| options: _SupportsGetStrWithDefault, optname: str, allowed: Container[_T], default: _T | None = None, normcase: bool = False | ||
| ) -> _T: ... | ||
| def get_bool_opt(options: _SupportsGetStrWithDefault, optname: str, default: bool | None = None) -> bool: ... | ||
| def get_int_opt(options: _SupportsGetStrWithDefault, optname: str, default: int | None = None) -> int: ... | ||
|
|
||
| # Return type and type of 'default' depend on the signature of the function whose **kwargs | ||
| # are being processed. | ||
| def get_list_opt( | ||
| options: _SupportsGetStrWithDefault, optname: str, default: list[Any] | tuple[Any, ...] | None = None | ||
| ) -> list[Any]: ... | ||
| def docstring_headline(obj: object) -> str: ... | ||
| def make_analysator(f: Callable[[str], float]) -> Callable[[str], float]: ... | ||
| def shebang_matches(text: str, regex: str) -> bool: ... | ||
| def doctype_matches(text: str, regex: str) -> bool: ... | ||
| def html_doctype_matches(text: str) -> bool: ... | ||
| def looks_like_xml(text: str) -> bool: ... | ||
| def surrogatepair(c: int) -> int: ... | ||
| def format_lines(var_name: str, seq: Iterable[str], raw: bool = False, indent_level: int = 0) -> str: ... | ||
| def duplicates_removed(it: Iterable[_H], already_seen: Container[_H] = ()) -> list[_H]: ... | ||
|
|
||
| class Future: | ||
| def get(self) -> None: ... | ||
|
|
||
| def guess_decode(text): ... | ||
| def guess_decode_from_terminal(text, term): ... | ||
| def terminal_encoding(term): ... | ||
| def guess_decode(text: bytes) -> tuple[str, str]: ... | ||
|
|
||
| # If 'term' has an 'encoding' attribute, it should be a str. Otherwise any object is accepted. | ||
| def guess_decode_from_terminal(text: bytes, term: Any) -> tuple[str, str]: ... | ||
| def terminal_encoding(term: Any) -> str: ... | ||
|
|
||
| class UnclosingTextIOWrapper(TextIOWrapper): | ||
| def close(self) -> None: ... |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: these are always called with literal values in practice (example), so I think using a literal type here provides some useful validation (even if a little verbose in the stubs)