summaryrefslogtreecommitdiffstats
path: root/contrib/python/Pygments/py3/pygments/lexers/python.py
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2026-05-20 14:32:16 +0300
committerrobot-piglet <[email protected]>2026-05-20 16:18:53 +0300
commit4a4ff781d4a9d3a49658e7aa494b0683dcb73e3b (patch)
tree7f1b851067a3043f388a9848013f47a89f14e756 /contrib/python/Pygments/py3/pygments/lexers/python.py
parentd0fa929c8414276a05083a1e5b06f690b3c8fac0 (diff)
Intermediate changes
commit_hash:1f540eb64a7d0f5f2171dadb7b44f303876ddc85
Diffstat (limited to 'contrib/python/Pygments/py3/pygments/lexers/python.py')
-rw-r--r--contrib/python/Pygments/py3/pygments/lexers/python.py51
1 files changed, 27 insertions, 24 deletions
diff --git a/contrib/python/Pygments/py3/pygments/lexers/python.py b/contrib/python/Pygments/py3/pygments/lexers/python.py
index 287305c75cc..805f6ff2ac7 100644
--- a/contrib/python/Pygments/py3/pygments/lexers/python.py
+++ b/contrib/python/Pygments/py3/pygments/lexers/python.py
@@ -4,7 +4,7 @@
Lexers for Python and related languages.
- :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -33,7 +33,7 @@ class PythonLexer(RegexLexer):
name = 'Python'
url = 'https://www.python.org'
- aliases = ['python', 'py', 'sage', 'python3', 'py3', 'bazel', 'starlark']
+ aliases = ['python', 'py', 'sage', 'python3', 'py3', 'bazel', 'starlark', 'pyi']
filenames = [
'*.py',
'*.pyw',
@@ -109,11 +109,11 @@ class PythonLexer(RegexLexer):
(r'\\', Text),
include('keywords'),
include('soft-keywords'),
- (r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'funcname'),
- (r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'classname'),
- (r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text),
+ (r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'funcname'),
+ (r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'classname'),
+ (r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
'fromimport'),
- (r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text),
+ (r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
'import'),
include('expr'),
],
@@ -329,14 +329,14 @@ class PythonLexer(RegexLexer):
(uni_name, Name.Class, '#pop'),
],
'import': [
- (r'(\s+)(as)(\s+)', bygroups(Text, Keyword, Text)),
+ (r'(\s+)(as)(\s+)', bygroups(Whitespace, Keyword, Whitespace)),
(r'\.', Name.Namespace),
(uni_name, Name.Namespace),
- (r'(\s*)(,)(\s*)', bygroups(Text, Operator, Text)),
+ (r'(\s*)(,)(\s*)', bygroups(Whitespace, Operator, Whitespace)),
default('#pop') # all else: go back
],
'fromimport': [
- (r'(\s+)(import)\b', bygroups(Text, Keyword.Namespace), '#pop'),
+ (r'(\s+)(import)\b', bygroups(Whitespace, Keyword.Namespace), '#pop'),
(r'\.', Name.Namespace),
# if None occurs here, it's "raise x from None", since None can
# never be a module name
@@ -459,11 +459,11 @@ class Python2Lexer(RegexLexer):
(r'(in|is|and|or|not)\b', Operator.Word),
(r'!=|==|<<|>>|[-~+/*%=<>&^|.]', Operator),
include('keywords'),
- (r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'funcname'),
- (r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Text), 'classname'),
- (r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text),
+ (r'(def)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'funcname'),
+ (r'(class)((?:\s|\\\s)+)', bygroups(Keyword, Whitespace), 'classname'),
+ (r'(from)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
'fromimport'),
- (r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Text),
+ (r'(import)((?:\s|\\\s)+)', bygroups(Keyword.Namespace, Whitespace),
'import'),
include('builtins'),
include('magicfuncs'),
@@ -635,6 +635,7 @@ class Python2Lexer(RegexLexer):
def analyse_text(text):
return shebang_matches(text, r'pythonw?2(\.\d)?')
+
class _PythonConsoleLexerBase(RegexLexer):
name = 'Python console session'
aliases = ['pycon', 'python-console']
@@ -671,6 +672,7 @@ class _PythonConsoleLexerBase(RegexLexer):
],
}
+
class PythonConsoleLexer(DelegatingLexer):
"""
For Python console output or doctests, such as:
@@ -719,6 +721,7 @@ class PythonConsoleLexer(DelegatingLexer):
super().__init__(pylexer, _PythonConsoleLexerBase, Other.Code, **options)
super().__init__(tblexer, _ReplaceInnerCode, Other.Traceback, **options)
+
class PythonTracebackLexer(RegexLexer):
"""
For Python 3.x tracebacks, with support for chained exceptions.
@@ -851,16 +854,16 @@ class CythonLexer(RegexLexer):
bygroups(Punctuation, Keyword.Type, Punctuation)),
(r'!=|==|<<|>>|[-~+/*%=<>&^|.?]', Operator),
(r'(from)(\d+)(<=)(\s+)(<)(\d+)(:)',
- bygroups(Keyword, Number.Integer, Operator, Name, Operator,
+ bygroups(Keyword, Number.Integer, Operator, Whitespace, Operator,
Name, Punctuation)),
include('keywords'),
- (r'(def|property)(\s+)', bygroups(Keyword, Text), 'funcname'),
- (r'(cp?def)(\s+)', bygroups(Keyword, Text), 'cdef'),
+ (r'(def|property)(\s+)', bygroups(Keyword, Whitespace), 'funcname'),
+ (r'(cp?def)(\s+)', bygroups(Keyword, Whitespace), 'cdef'),
# (should actually start a block with only cdefs)
(r'(cdef)(:)', bygroups(Keyword, Punctuation)),
- (r'(class|struct)(\s+)', bygroups(Keyword, Text), 'classname'),
- (r'(from)(\s+)', bygroups(Keyword, Text), 'fromimport'),
- (r'(c?import)(\s+)', bygroups(Keyword, Text), 'import'),
+ (r'(class|struct)(\s+)', bygroups(Keyword, Whitespace), 'classname'),
+ (r'(from)(\s+)', bygroups(Keyword, Whitespace), 'fromimport'),
+ (r'(c?import)(\s+)', bygroups(Keyword, Whitespace), 'import'),
include('builtins'),
include('backtick'),
('(?:[rR]|[uU][rR]|[rR][uU])"""', String, 'tdqs'),
@@ -938,9 +941,9 @@ class CythonLexer(RegexLexer):
(r'(public|readonly|extern|api|inline)\b', Keyword.Reserved),
(r'(struct|enum|union|class)\b', Keyword),
(r'([a-zA-Z_]\w*)(\s*)(?=[(:#=]|$)',
- bygroups(Name.Function, Text), '#pop'),
+ bygroups(Name.Function, Whitespace), '#pop'),
(r'([a-zA-Z_]\w*)(\s*)(,)',
- bygroups(Name.Function, Text, Punctuation)),
+ bygroups(Name.Function, Whitespace, Punctuation)),
(r'from\b', Keyword, '#pop'),
(r'as\b', Keyword),
(r':', Punctuation, '#pop'),
@@ -952,13 +955,13 @@ class CythonLexer(RegexLexer):
(r'[a-zA-Z_]\w*', Name.Class, '#pop')
],
'import': [
- (r'(\s+)(as)(\s+)', bygroups(Text, Keyword, Text)),
+ (r'(\s+)(as)(\s+)', bygroups(Whitespace, Keyword, Whitespace)),
(r'[a-zA-Z_][\w.]*', Name.Namespace),
- (r'(\s*)(,)(\s*)', bygroups(Text, Operator, Text)),
+ (r'(\s*)(,)(\s*)', bygroups(Whitespace, Operator, Whitespace)),
default('#pop') # all else: go back
],
'fromimport': [
- (r'(\s+)(c?import)\b', bygroups(Text, Keyword), '#pop'),
+ (r'(\s+)(c?import)\b', bygroups(Whitespace, Keyword), '#pop'),
(r'[a-zA-Z_.][\w.]*', Name.Namespace),
# ``cdef foo from "header"``, or ``for foo from 0 < i < 10``
default('#pop'),