Skip to content

Commit 91923b4

Browse files
committed
Tear out remainders of Python 2 support
1 parent 9c003c9 commit 91923b4

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

python/opencc/__init__.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
from __future__ import absolute_import, unicode_literals
2-
31
import os
4-
import sys
52

6-
try:
7-
import opencc_clib
8-
except ImportError:
9-
from opencc.clib import opencc_clib
3+
from opencc.clib import opencc_clib
104

11-
__all__ = ['OpenCC', 'CONFIGS', '__version__']
5+
__all__ = ['CONFIGS', 'OpenCC', '__version__']
126

137
__version__ = opencc_clib.__version__
148
_this_dir = os.path.dirname(os.path.abspath(__file__))
159
_opencc_share_dir = os.path.join(_this_dir, 'clib', 'share', 'opencc')
16-
_opencc_rootdir = os.path.abspath(os.path.join(_this_dir, '..', '..'))
10+
_opencc_rootdir = os.path.abspath(os.path.join(_this_dir, '..', '..'))
1711
_opencc_configdir = os.path.join(_opencc_rootdir, 'data', 'config')
1812

19-
if sys.version_info.major == 2:
20-
text_type = unicode # noqa
21-
else:
22-
text_type = str
23-
2413
if os.path.isdir(_opencc_share_dir):
2514
CONFIGS = [f for f in os.listdir(_opencc_share_dir) if f.endswith('.json')]
2615
elif os.path.isdir(_opencc_configdir):
@@ -36,7 +25,7 @@ def _append_path_to_env(name: str, path: str) -> None:
3625
if value == '':
3726
value = path
3827
else:
39-
value += ':' + path
28+
value += f':{path}'
4029
os.environ[name] = value
4130

4231

@@ -49,10 +38,9 @@ def __init__(self, config: str = 't2s') -> None:
4938
config_under_share_dir = os.path.join(_opencc_share_dir, config)
5039
if os.path.isfile(config_under_share_dir):
5140
config = config_under_share_dir
52-
super(OpenCC, self).__init__(config)
41+
super().__init__(config)
5342
self.config = config
5443

55-
def convert(self, text):
56-
if isinstance(text, text_type):
57-
text = text.encode('utf-8')
58-
return super(OpenCC, self).convert(text, len(text))
44+
def convert(self, text: str):
45+
byte_text = text.encode('utf-8')
46+
return super().convert(byte_text, len(byte_text))

python/tests/test_opencc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import unicode_literals
2-
31
import json
42
import os
53
import pytest

0 commit comments

Comments
 (0)