Skip to content

Commit

Permalink
Patch pygments.Formatter.__class_getitem__ in Pygments 2.17
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jul 30, 2024
1 parent f1d3c3f commit 865b513
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Release 8.0.1 (in development)
Bugs fixed
----------

* Patch ``pygments.Formatter.__class_getitem__`` in Pygments 2.17.
Patch by Adam Turner.

Release 8.0.0 (released Jul 29, 2024)
=====================================
Expand Down
6 changes: 6 additions & 0 deletions sphinx/highlighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from importlib import import_module
from typing import TYPE_CHECKING, Any

import pygments
from pygments import highlight
from pygments.filters import ErrorToken
from pygments.formatters import HtmlFormatter, LatexFormatter
Expand All @@ -30,6 +31,11 @@
from pygments.lexer import Lexer
from pygments.style import Style

if tuple(map(int, pygments.__version__.split('.')))[:2] < (2, 18):
from pygments.formatter import Formatter

Formatter.__class_getitem__ = lambda cls, name: cls

logger = logging.getLogger(__name__)

lexers: dict[str, Lexer] = {}
Expand Down
5 changes: 5 additions & 0 deletions tests/test_highlighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

from unittest import mock

import pygments
from pygments.formatters.html import HtmlFormatter
from pygments.lexer import RegexLexer
from pygments.token import Name, Text

from sphinx.highlighting import PygmentsBridge

if tuple(map(int, pygments.__version__.split('.')))[:2] < (2, 18):
from pygments.formatter import Formatter
Formatter.__class_getitem__ = lambda cls, name: cls


class MyLexer(RegexLexer):
name = 'testlexer'
Expand Down

0 comments on commit 865b513

Please sign in to comment.