Skip to content

Commit 865b513

Browse files
committed
Patch pygments.Formatter.__class_getitem__ in Pygments 2.17
1 parent f1d3c3f commit 865b513

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGES.rst

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Release 8.0.1 (in development)
44
Bugs fixed
55
----------
66

7+
* Patch ``pygments.Formatter.__class_getitem__`` in Pygments 2.17.
8+
Patch by Adam Turner.
79

810
Release 8.0.0 (released Jul 29, 2024)
911
=====================================

sphinx/highlighting.py

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from importlib import import_module
77
from typing import TYPE_CHECKING, Any
88

9+
import pygments
910
from pygments import highlight
1011
from pygments.filters import ErrorToken
1112
from pygments.formatters import HtmlFormatter, LatexFormatter
@@ -30,6 +31,11 @@
3031
from pygments.lexer import Lexer
3132
from pygments.style import Style
3233

34+
if tuple(map(int, pygments.__version__.split('.')))[:2] < (2, 18):
35+
from pygments.formatter import Formatter
36+
37+
Formatter.__class_getitem__ = lambda cls, name: cls
38+
3339
logger = logging.getLogger(__name__)
3440

3541
lexers: dict[str, Lexer] = {}

tests/test_highlighting.py

+5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
from unittest import mock
44

5+
import pygments
56
from pygments.formatters.html import HtmlFormatter
67
from pygments.lexer import RegexLexer
78
from pygments.token import Name, Text
89

910
from sphinx.highlighting import PygmentsBridge
1011

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

1217
class MyLexer(RegexLexer):
1318
name = 'testlexer'

0 commit comments

Comments
 (0)