Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion stubs/Pygments/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,34 @@ pygments.lexer.LexerMeta.__new__
pygments.style.StyleMeta.__new__

# Defined in lexer classes, intended to be used as static method, but doesn't use @staticmethod
pygments.lexer.LexerMeta.analyse_text
pygments.lexer.Lexer(Meta)?.analyse_text

# Inheriting from tuple is weird
pygments.token._TokenType.__init__

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

# Class attributes that are typed in the metaclass instead. See comment in stubs.
pygments.lexer.Lexer.name
pygments.lexer.Lexer.aliases
pygments.lexer.Lexer.filenames
pygments.lexer.Lexer.alias_filenames
pygments.lexer.Lexer.mimetypes
pygments.lexer.Lexer.priority
pygments.lexer.Lexer.url
pygments.lexer.Lexer.version_added
pygments.style.Style.background_color
pygments.style.Style.highlight_color
pygments.style.Style.line_number_color
pygments.style.Style.line_number_background_color
pygments.style.Style.line_number_special_color
pygments.style.Style.line_number_special_background_color
pygments.style.Style.styles
pygments.style.Style.name
pygments.style.Style.aliases
pygments.style.Style.web_style_gallery_exclude

# Individual lexers and styles submodules are not stubbed at this time.
pygments\.lexers\.(?!get_|find_|load_|guess_).*
pygments\.styles\.(?!get_).*
1 change: 0 additions & 1 deletion stubs/Pygments/METADATA.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ partial_stub = true

[tool.stubtest]
stubtest_dependencies = ["sphinx"]
ignore_missing_stub = true
6 changes: 5 additions & 1 deletion stubs/Pygments/pygments/formatter.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import types
from _typeshed import Incomplete
from typing import Generic, TypeVar, overload
from typing import Any, Generic, TypeVar, overload

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

__all__ = ["Formatter"]

class Formatter(Generic[_T]):
name: Incomplete
aliases: Incomplete
Expand All @@ -19,5 +22,6 @@ class Formatter(Generic[_T]):
def __init__(self: Formatter[bytes], *, encoding: str, outencoding: None = None, **options) -> None: ...
@overload
def __init__(self: Formatter[bytes], *, encoding: None = None, outencoding: str, **options) -> None: ...
def __class_getitem__(cls, name: Any) -> types.GenericAlias: ...
def get_style_defs(self, arg: str = ""): ...
def format(self, tokensource, outfile): ...
26 changes: 26 additions & 0 deletions stubs/Pygments/pygments/formatters/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from collections.abc import Generator

from ..formatter import Formatter
from .bbcode import BBCodeFormatter as BBCodeFormatter
from .groff import GroffFormatter as GroffFormatter
from .html import HtmlFormatter as HtmlFormatter
from .img import (
BmpImageFormatter as BmpImageFormatter,
Expand All @@ -19,6 +20,31 @@ from .svg import SvgFormatter as SvgFormatter
from .terminal import TerminalFormatter as TerminalFormatter
from .terminal256 import Terminal256Formatter as Terminal256Formatter, TerminalTrueColorFormatter as TerminalTrueColorFormatter

__all__ = [
"get_formatter_by_name",
"get_formatter_for_filename",
"get_all_formatters",
"load_formatter_from_file",
"BBCodeFormatter",
"BmpImageFormatter",
"GifImageFormatter",
"GroffFormatter",
"HtmlFormatter",
"IRCFormatter",
"ImageFormatter",
"JpgImageFormatter",
"LatexFormatter",
"NullFormatter",
"PangoMarkupFormatter",
"RawTokenFormatter",
"RtfFormatter",
"SvgFormatter",
"Terminal256Formatter",
"TerminalFormatter",
"TerminalTrueColorFormatter",
"TestcaseFormatter",
]

def get_all_formatters() -> Generator[type[Formatter[Incomplete]]]: ...
def get_formatter_by_name(_alias, **options): ...
def load_formatter_from_file(filename, formattername: str = "CustomFormatter", **options): ...
Expand Down
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/bbcode.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from pygments.formatter import Formatter

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

__all__ = ["BBCodeFormatter"]

class BBCodeFormatter(Formatter[_T]):
name: str
aliases: Incomplete
Expand Down
18 changes: 18 additions & 0 deletions stubs/Pygments/pygments/formatters/groff.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from _typeshed import SupportsWrite
from collections.abc import Iterable
from typing import TypeVar

from pygments.formatter import Formatter
from pygments.token import _TokenType

__all__ = ["GroffFormatter"]

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

class GroffFormatter(Formatter[_T]):
monospaced: bool
linenos: bool
wrap: int
styles: dict[_TokenType, tuple[str, str]]
def __init__(self, **options) -> None: ...
def format_unencoded(self, tokensource: Iterable[tuple[_TokenType, str]], outfile: SupportsWrite[str]) -> None: ...
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/html.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from pygments.formatter import Formatter

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

__all__ = ["HtmlFormatter"]

class HtmlFormatter(Formatter[_T]):
name: str
aliases: Incomplete
Expand Down
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/img.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from pygments.formatter import Formatter

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

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

class PilNotAvailable(ImportError): ...
class FontNotFound(Exception): ...

Expand Down
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/irc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from pygments.formatter import Formatter

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

__all__ = ["IRCFormatter"]

class IRCFormatter(Formatter[_T]):
name: str
aliases: Incomplete
Expand Down
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/latex.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ from pygments.lexer import Lexer

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

__all__ = ["LatexFormatter"]

class LatexFormatter(Formatter[_T]):
name: str
aliases: Incomplete
Expand Down
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/other.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from pygments.formatter import Formatter

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

__all__ = ["NullFormatter", "RawTokenFormatter", "TestcaseFormatter"]

class NullFormatter(Formatter[_T]):
name: str
aliases: Incomplete
Expand Down
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/pangomarkup.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from pygments.formatter import Formatter

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

__all__ = ["PangoMarkupFormatter"]

class PangoMarkupFormatter(Formatter[_T]):
name: str
aliases: Incomplete
Expand Down
4 changes: 4 additions & 0 deletions stubs/Pygments/pygments/formatters/rtf.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ from pygments.formatter import Formatter

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

__all__ = ["RtfFormatter"]

class RtfFormatter(Formatter[_T]):
name: str
aliases: Incomplete
filenames: Incomplete
fontface: Incomplete
fontsize: Incomplete
@staticmethod
def hex_to_rtf_color(hex_color: str) -> str: ...
def format_unencoded(self, tokensource, outfile) -> None: ...
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/svg.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from pygments.formatter import Formatter

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

__all__ = ["SvgFormatter"]

class SvgFormatter(Formatter[_T]):
name: str
aliases: Incomplete
Expand Down
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/terminal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from pygments.formatter import Formatter

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

__all__ = ["TerminalFormatter"]

class TerminalFormatter(Formatter[_T]):
name: str
aliases: Incomplete
Expand Down
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/formatters/terminal256.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from pygments.formatter import Formatter

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

__all__ = ["Terminal256Formatter", "TerminalTrueColorFormatter"]

class EscapeSequence:
fg: Incomplete
bg: Incomplete
Expand Down
27 changes: 23 additions & 4 deletions stubs/Pygments/pygments/lexer.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
from _typeshed import Incomplete
from collections.abc import Iterable, Iterator, Sequence
from re import RegexFlag
from typing import ClassVar
from re import Pattern, RegexFlag
from typing import ClassVar, Final

from pygments.token import _TokenType
from pygments.util import Future

__all__ = [
"Lexer",
"RegexLexer",
"ExtendedRegexLexer",
"DelegatingLexer",
"LexerContext",
"include",
"inherit",
"bygroups",
"using",
"this",
"default",
"words",
"line_re",
]

line_re: Final[Pattern[str]]

class LexerMeta(type):
def __new__(cls, name, bases, d): ...
def analyse_text(self, text: str) -> float: ... # actually defined in class Lexer
# ClassVars of Lexer, but same situation as with StyleMeta and Style
name: str
name: str # Set to None in Lexer, but always overridden with a non-None value in subclasses.
aliases: Sequence[str] # not intended mutable
filenames: Sequence[str]
alias_filenames: Sequence[str]
mimetypes: Sequence[str]
priority: float
url: str | None
url: str # Set to None in Lexer, but always overridden with a non-None value in subclasses.
version_added: str # Set to None in Lexer, but always overridden with a non-None value in subclasses.

class Lexer(metaclass=LexerMeta):
options: Incomplete
Expand Down
2 changes: 2 additions & 0 deletions stubs/Pygments/pygments/modeline.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__all__ = ["get_filetype_from_buffer"]

def get_filetype_from_buffer(buf, max_lines: int = 5): ...
1 change: 1 addition & 0 deletions stubs/Pygments/pygments/sphinxext.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FILTERDOC: str

class PygmentsDoc(Directive):
filenames: set[str]
def document_lexers_overview(self) -> str: ...
def document_lexers(self) -> str: ...
def document_formatters(self) -> str: ...
def document_filters(self) -> str: ...
Expand Down