Skip to content

Commit 07ec4e9

Browse files
committed
Remove PythonLexer from bpython._py3compat
1 parent 8f77951 commit 07ec4e9

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

bpython/_py3compat.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
2828
Defines the following attributes:
2929
30-
- PythonLexer: Pygment's Python lexer matching the hosting runtime's
31-
Python version.
3230
- py3: True if the hosting Python runtime is of Python version 3 or later
3331
"""
3432

@@ -39,12 +37,6 @@
3937
py3 = sys.version_info[0] == 3
4038

4139

42-
if py3:
43-
from pygments.lexers import Python3Lexer as PythonLexer
44-
else:
45-
from pygments.lexers import PythonLexer
46-
47-
4840
if py3 or sys.version_info[:3] >= (2, 7, 3):
4941

5042
def prepare_for_exec(arg, encoding=None):

bpython/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
# These are used for syntax highlighting
6363
from pygments import format
6464
from pygments.formatters import TerminalFormatter
65-
from ._py3compat import PythonLexer, py3
65+
from pygments.lexers import Python3Lexer
66+
from ._py3compat import py3
6667
from pygments.token import Token
6768
from .formatter import BPythonFormatter
6869

@@ -1001,7 +1002,7 @@ def p_key(self, key):
10011002
else:
10021003
if config.highlight_show_source:
10031004
source = format(
1004-
PythonLexer().get_tokens(source), TerminalFormatter()
1005+
Python3Lexer().get_tokens(source), TerminalFormatter()
10051006
)
10061007
page(source)
10071008
return ""

bpython/curtsiesfrontend/repl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import unicodedata
1313

1414
from pygments import format as pygformat
15-
from bpython._py3compat import PythonLexer
15+
from pygments.lexers import Python3Lexer
1616
from pygments.formatters import TerminalFormatter
1717

1818
from wcwidth import wcswidth
@@ -2013,7 +2013,7 @@ def show_source(self):
20132013
else:
20142014
if self.config.highlight_show_source:
20152015
source = pygformat(
2016-
PythonLexer().get_tokens(source), TerminalFormatter()
2016+
Python3Lexer().get_tokens(source), TerminalFormatter()
20172017
)
20182018
self.pager(source)
20192019

bpython/inspection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
from collections import namedtuple
3030

3131
from pygments.token import Token
32+
from pygments.lexers import Python3Lexer
3233
from types import MemberDescriptorType
3334

34-
from ._py3compat import PythonLexer, py3
35+
from ._py3compat import py3
3536
from .lazyre import LazyReCompile
3637

3738
if not py3:
@@ -134,7 +135,7 @@ def __repr__(self):
134135

135136

136137
def parsekeywordpairs(signature):
137-
tokens = PythonLexer().get_tokens(signature)
138+
tokens = Python3Lexer().get_tokens(signature)
138139
preamble = True
139140
stack = []
140141
substack = []

bpython/repl.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
from types import ModuleType
4141

4242
from pygments.token import Token
43+
from pygments.lexers import Python3Lexer
4344

4445
from . import autocomplete
4546
from . import inspection
46-
from ._py3compat import PythonLexer, py3, prepare_for_exec
47+
from ._py3compat import py3, prepare_for_exec
4748
from .clipboard import get_clipboard, CopyFailed
4849
from .config import getpreferredencoding
4950
from .formatter import Parenthesis
@@ -572,7 +573,7 @@ def _funcname_and_argnum(cls, line):
572573
# argument so we're done counting
573574
stack = [["", "", 0, ""]]
574575
try:
575-
for (token, value) in PythonLexer().get_tokens(line):
576+
for (token, value) in Python3Lexer().get_tokens(line):
576577
if token is Token.Punctuation:
577578
if value in "([{":
578579
stack.append(["", "", 0, value])
@@ -1079,7 +1080,7 @@ def tokenize(self, s, newline=False):
10791080
if self.cpos:
10801081
cursor += 1
10811082
stack = list()
1082-
all_tokens = list(PythonLexer().get_tokens(source))
1083+
all_tokens = list(Python3Lexer().get_tokens(source))
10831084
# Unfortunately, Pygments adds a trailing newline and strings with
10841085
# no size, so strip them
10851086
while not all_tokens[-1][1]:
@@ -1250,7 +1251,7 @@ def next_indentation(line, tab_length):
12501251
def next_token_inside_string(code_string, inside_string):
12511252
"""Given a code string s and an initial state inside_string, return
12521253
whether the next token will be inside a string or not."""
1253-
for token, value in PythonLexer().get_tokens(code_string):
1254+
for token, value in Python3Lexer().get_tokens(code_string):
12541255
if token is Token.String:
12551256
value = value.lstrip("bBrRuU")
12561257
if value in ['"""', "'''", '"', "'"]:

0 commit comments

Comments
 (0)