Mercurial > hgrepos > Python > libs > pygments-lexer-pseudocode2
changeset 73:a2a56d08b860
FIX: Python 2 needs a "staticmethod" on "op_fixed()" when called via the LexBase.
Python 3 does not allow this. Implement proper decoration depending on the
Python version.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 28 Apr 2026 19:29:28 +0200 |
| parents | 206017a08ed7 |
| children | c1357674622d |
| files | pygments_lexer_pseudocode2/bases.py |
| diffstat | 1 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/pygments_lexer_pseudocode2/bases.py Tue Apr 28 19:14:17 2026 +0200 +++ b/pygments_lexer_pseudocode2/bases.py Tue Apr 28 19:29:28 2026 +0200 @@ -8,11 +8,16 @@ __all__ = ["LexBase", "uni_name", "py_innerstring_rules", "py_name_rules"] +import sys + from pygments import unistring from pygments.lexer import RegexLexer, combined, bygroups, include from pygments.token import (Comment, Error, Name, Number, Other, String) +PY2 = sys.version_info[0] <= 2 + + # # SPDX-SnippetBegin # SPDX-License-Identifier: BSD-2-Clause @@ -23,6 +28,14 @@ uni_name = "[%s][%s]*" % (unistring.xid_start, unistring.xid_continue) +"""PY3 allows no @staticmethod but PY2 needs it.""" +if PY2: + _staticmethod = staticmethod +else: + def _staticmethod(fn): + return fn + + def py_innerstring_rules(ttype): return [ # the old style '%s' % (...) string formatting (still valid in Py3) @@ -73,6 +86,7 @@ if False: yield match.start(), Other, "" + @_staticmethod def op_fixed(toktype, value): """Unconditionally yield a given token type and value."""
