Skip to content

Commit

Permalink
Merge pull request #2665 from Akuli/class-getitem
Browse files Browse the repository at this point in the history
Add a __class_getitem__ to Formatter
  • Loading branch information
Anteru committed Mar 24, 2024
2 parents 1e72671 + 0f40614 commit 2b9936c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pygments/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,8 @@ def format(self, tokensource, outfile):
# wrap the outfile in a StreamWriter
outfile = codecs.lookup(self.encoding)[3](outfile)
return self.format_unencoded(tokensource, outfile)

# Allow writing Formatter[str] or Formatter[bytes]. That's equivalent to
# Formatter. This helps when using third-party type stubs from typeshed.
def __class_getitem__(cls, name):
return cls

0 comments on commit 2b9936c

Please sign in to comment.