Skip to content

Commit 0a72904

Browse files
committed
Tear out remainders of Python 2 support
1 parent 9c003c9 commit 0a72904

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

python/opencc/__init__.py

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

63
try:
7-
import opencc_clib
4+
import opencc_clib
85
except ImportError:
96
from opencc.clib import opencc_clib
107

11-
__all__ = ['OpenCC', 'CONFIGS', '__version__']
8+
__all__ = ['CONFIGS', 'OpenCC', '__version__']
129

1310
__version__ = opencc_clib.__version__
1411
_this_dir = os.path.dirname(os.path.abspath(__file__))
1512
_opencc_share_dir = os.path.join(_this_dir, 'clib', 'share', 'opencc')
16-
_opencc_rootdir = os.path.abspath(os.path.join(_this_dir, '..', '..'))
13+
_opencc_rootdir = os.path.abspath(os.path.join(_this_dir, '..', '..'))
1714
_opencc_configdir = os.path.join(_opencc_rootdir, 'data', 'config')
1815

19-
if sys.version_info.major == 2:
20-
text_type = unicode # noqa
21-
else:
22-
text_type = str
23-
2416
if os.path.isdir(_opencc_share_dir):
2517
CONFIGS = [f for f in os.listdir(_opencc_share_dir) if f.endswith('.json')]
2618
elif os.path.isdir(_opencc_configdir):
@@ -36,7 +28,7 @@ def _append_path_to_env(name: str, path: str) -> None:
3628
if value == '':
3729
value = path
3830
else:
39-
value += ':' + path
31+
value += f':{path}'
4032
os.environ[name] = value
4133

4234

@@ -49,10 +41,9 @@ def __init__(self, config: str = 't2s') -> None:
4941
config_under_share_dir = os.path.join(_opencc_share_dir, config)
5042
if os.path.isfile(config_under_share_dir):
5143
config = config_under_share_dir
52-
super(OpenCC, self).__init__(config)
44+
super().__init__(config)
5345
self.config = config
5446

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))
47+
def convert(self, text: str):
48+
byte_text = text.encode('utf-8')
49+
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)