-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
pygments: add typing annotation for missing base files of pygments #14832
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
lev-blit
wants to merge
4
commits into
python:main
Choose a base branch
from
lev-blit:feature/pygments-fill-typing
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.
+255
−153
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
390628e
pygments: add typing annotation for missing base files of pygments
lev-blit 45b0765
add filters + formatters __init__.pyi
lev-blit 657943f
more fixes
lev-blit 77ad3a6
allow words and not only str, and allow default instead of whole thing
lev-blit 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,8 +1,10 @@ | ||
import argparse | ||
import sys | ||
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] = sys.argv) -> 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,8 @@ | ||
from typing import Any | ||
|
||
esc: str | ||
codes: Any | ||
dark_colors: Any | ||
light_colors: Any | ||
codes: dict[str, str] | ||
dark_colors: list[str] | ||
light_colors: 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,18 +1,20 @@ | ||
from collections.abc import Iterable, Iterator | ||
from collections.abc import Callable, Generator, Iterable, Iterator | ||
from typing import Any | ||
|
||
from pygments.lexer import Lexer | ||
from pygments.token import _TokenType | ||
|
||
def apply_filters(stream, filters, lexer=None): ... | ||
def simplefilter(f): ... | ||
def apply_filters( | ||
stream: Callable[[], Iterator[tuple[_TokenType, str]]], filters: list[Filter], lexer: Lexer | None = None | ||
) -> Generator[tuple[_TokenType, str], None, tuple[_TokenType, str]]: ... | ||
def simplefilter(f: Callable[..., Any]) -> type[FunctionFilter]: ... | ||
|
||
class Filter: | ||
options: Any | ||
def __init__(self, **options) -> None: ... | ||
def __init__(self, **options: Any) -> None: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, str]]: ... | ||
|
||
class FunctionFilter(Filter): | ||
function: Any | ||
def __init__(self, **options) -> None: ... | ||
function: Callable[..., Any] | None = None | ||
def __init__(self, **options: Any) -> None: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, 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,58 +1,58 @@ | ||
from collections.abc import Generator, Iterable, Iterator | ||
from collections.abc import Callable, Generator, Iterable, Iterator | ||
from typing import Any | ||
|
||
from pygments.filter import Filter | ||
from pygments.lexer import Lexer | ||
from pygments.token import _TokenType | ||
|
||
def find_filter_class(filtername): ... | ||
def get_filter_by_name(filtername, **options): ... | ||
def find_filter_class(filtername: str) -> type[Filter]: ... | ||
def get_filter_by_name(filtername: str, **options: Any) -> Filter: ... | ||
def get_all_filters() -> Generator[str, None, None]: ... | ||
|
||
class CodeTagFilter(Filter): | ||
tag_re: Any | ||
def __init__(self, **options) -> None: ... | ||
def __init__(self, **options: Any) -> None: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, str]]: ... | ||
|
||
class SymbolFilter(Filter): | ||
latex_symbols: Any | ||
isabelle_symbols: Any | ||
lang_map: Any | ||
symbols: Any | ||
def __init__(self, **options) -> None: ... | ||
latex_symbols: dict[str, str] | ||
isabelle_symbols: dict[str, str] | ||
lang_map: dict[str, dict[str, str]] | ||
symbols: dict[str, str] | ||
def __init__(self, **options: Any) -> None: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, str]]: ... | ||
|
||
class KeywordCaseFilter(Filter): | ||
convert: Any | ||
def __init__(self, **options) -> None: ... | ||
convert: Callable[[str], str] | ||
def __init__(self, **options: Any) -> None: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, str]]: ... | ||
|
||
class NameHighlightFilter(Filter): | ||
names: Any | ||
tokentype: Any | ||
def __init__(self, **options) -> None: ... | ||
names: set[str] | ||
tokentype: _TokenType | ||
def __init__(self, **options: Any) -> None: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, str]]: ... | ||
|
||
class ErrorToken(Exception): ... | ||
|
||
class RaiseOnErrorTokenFilter(Filter): | ||
exception: Any | ||
def __init__(self, **options) -> None: ... | ||
exception: type[Exception] | ||
def __init__(self, **options: Any) -> None: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, str]]: ... | ||
|
||
class VisibleWhitespaceFilter(Filter): | ||
wstt: Any | ||
def __init__(self, **options) -> None: ... | ||
wstt: bool | ||
def __init__(self, **options: Any) -> None: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, str]]: ... | ||
|
||
class GobbleFilter(Filter): | ||
n: Any | ||
def __init__(self, **options) -> None: ... | ||
def gobble(self, value, left): ... | ||
n: int | ||
def __init__(self, **options: Any) -> None: ... | ||
def gobble(self, value: str, left: int) -> tuple[str, int]: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, str]]: ... | ||
|
||
class TokenMergeFilter(Filter): | ||
def __init__(self, **options) -> None: ... | ||
def __init__(self, **options: Any) -> None: ... | ||
def filter(self, lexer: Lexer, stream: Iterable[tuple[_TokenType, str]]) -> Iterator[tuple[_TokenType, str]]: ... | ||
|
||
FILTERS: Any | ||
FILTERS: dict[str, type[Filter]] |
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,31 @@ | ||
from _io import _TextIOBase | ||
from collections.abc import Iterator | ||
from types import GenericAlias | ||
from typing import Any, Generic, TypeVar, overload | ||
|
||
from pygments.style import Style | ||
from pygments.token import _TokenType | ||
|
||
__all__ = ["Formatter"] | ||
|
||
_T = TypeVar("_T", str, bytes) | ||
|
||
class Formatter(Generic[_T]): | ||
name: Any | ||
aliases: Any | ||
filenames: Any | ||
name: str | None = None | ||
aliases: list[str] | ||
filenames: list[str] | ||
unicodeoutput: bool | ||
style: Any | ||
full: Any | ||
title: Any | ||
encoding: Any | ||
options: Any | ||
style: type[Style] | ||
full: bool | ||
title: str | ||
encoding: str | ||
options: dict[str, Any] | ||
@overload | ||
def __init__(self: Formatter[str], *, encoding: None = None, outencoding: None = None, **options) -> None: ... | ||
def __init__(self: Formatter[str], *, encoding: None = None, outencoding: None = None, **options: Any) -> None: ... | ||
@overload | ||
def __init__(self: Formatter[bytes], *, encoding: str, outencoding: None = None, **options) -> None: ... | ||
def __init__(self: Formatter[bytes], *, encoding: str, outencoding: None = None, **options: Any) -> None: ... | ||
@overload | ||
def __init__(self: Formatter[bytes], *, encoding: None = None, outencoding: str, **options) -> None: ... | ||
def get_style_defs(self, arg: str = ""): ... | ||
def format(self, tokensource, outfile): ... | ||
def __init__(self: Formatter[bytes], *, encoding: None = None, outencoding: str, **options: Any) -> None: ... | ||
def get_style_defs(self, arg: str = "") -> str: ... | ||
def format(self, tokensource: Iterator[tuple[_TokenType, str]], outfile: _TextIOBase) -> None: ... | ||
def __class_getitem__(cls, name: Any) -> GenericAlias: ... |
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ from .terminal import TerminalFormatter as TerminalFormatter | |
from .terminal256 import Terminal256Formatter as Terminal256Formatter, TerminalTrueColorFormatter as TerminalTrueColorFormatter | ||
|
||
def get_all_formatters() -> Generator[type[Formatter[Any]], None, None]: ... | ||
def get_formatter_by_name(_alias, **options): ... | ||
def load_formatter_from_file(filename, formattername: str = "CustomFormatter", **options): ... | ||
def get_formatter_for_filename(fn, **options): ... | ||
def find_formatter_class(alias: str) -> type[Formatter[Any]]: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, |
||
def get_formatter_by_name(_alias: str, **options: Any) -> Formatter[Any]: ... | ||
def load_formatter_from_file(filename: str, formattername: str = "CustomFormatter", **options: Any) -> Formatter[Any]: ... | ||
def get_formatter_for_filename(fn: str, **options: Any) -> Formatter[Any]: ... |
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 @@ | ||
from typing import Any | ||
|
||
FORMATTERS: Any | ||
FORMATTERS: dict[str, tuple[str, str, tuple[str, ...], tuple[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
Oops, something went wrong.
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.
Also applies to the other
**options: Any
annotations in this PR: In general, when usingAny
we need a comment, explaining the possible types or reason for using it. In this case probably something like this:See https://typing.python.org/en/latest/guides/writing_stubs.html#using-any-and-object for details.