8000 Merge pull request #1193 from stonebig/master · Tmusvit/winpython@7c886d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c886d6

Browse files
authored
Merge pull request winpython#1193 from stonebig/master
remove python2 complexity
2 parents c6eeba3 + 1a33b2e commit 7c886d6

File tree

5 files changed

+32
-112
lines changed

5 files changed

+32
-112
lines changed

winpython/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-----------------------------------------
55
66
Copyright (c) 2012-2013 Pierre Raybaut
7-
Copyright (c) 2014-2022+ The Winpython development team https://github.com/winpython/
7+
Copyright (c) 2014-2023+ The Winpython development team https://github.com/winpython/
88
99
Permission is hereby granted, free of charge, to any person
1010
obtaining a copy of this software and associated documentation
@@ -28,6 +28,6 @@
2828
OTHER DEALINGS IN THE SOFTWARE.
2929
"""
3030

31-
__version__ = '5.3.20230129'
31+
__version__ = '6.0.20230204'
3232
__license__ = __doc__
3333
__project_url__ = 'http://winpython.github.io/'

winpython/py3compat.py

Lines changed: 15 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@
2828
# ==============================================================================
2929
# Data types
3030
# ==============================================================================
31-
if PY2:
32-
# Python 2
33-
TEXT_TYPES = (str, unicode)
34-
INT_TYPES = (int, long)
35-
else:
31+
if True:
3632
# Python 3
3733
TEXT_TYPES = (str,)
3834
INT_TYPES = (int,)
@@ -42,29 +38,7 @@
4238
# ==============================================================================
4339
# Renamed/Reorganized modules
4440
# ==============================================================================
45-
if PY2:
46-
# Python 2
47-
import __builtin__ as builtins
48-
import ConfigParser as configparser
49-
50-
try:
51-
import _winreg as winreg
52-
except ImportError:
53-
pass
54-
from sys import maxint as maxsize
55-
56-
try:
57-
import CStringIO as io
58-
except ImportError:
59-
import StringIO as io
60-
try:
61-
import cPickle as pickle
62-
except ImportError:
63-
import pickle
64-
from UserDict import DictMixin as MutableMapping
65-
import thread as _thread
66-
import repr as reprlib
67-
else:
41+
if True:
6842
# Python 3
6943
import builtins
7044
import configparser
@@ -85,16 +59,7 @@
8559
# ==============================================================================
8660
# Strings
8761
# ==============================================================================
88-
if PY2:
89-
# Python 2
90-
import codecs
91-
92-
def u(obj):
93-
"""Make unicode object"""
94-
return codecs.unicode_escape_decode(obj)[0]
95-
96-
97-
else:
62+
if True:
9863
# Python 3
9964
def u(obj):
10065
"""Return string as it is"""
@@ -104,20 +69,14 @@ def u(obj):
10469
def is_text_string(obj):
10570
"""Return True if `obj` is a text string, False if it is anything else,
10671
like binary data (Python 3) or QString (Python 2, PyQt API #1)"""
107-
if PY2:
108-
# Python 2
109-
return isinstance(obj, basestring)
110-
else:
72+
if True:
11173
# Python 3
11274
return isinstance(obj, str)
11375

11476

11577
def is_binary_string(obj):
11678
"""Return True if `obj` is a binary string, False if it is anything else"""
117-
if PY2:
118-
# Python 2
119-
return isinstance(obj, str)
120-
else:
79+
if True:
12180
# Python 3
12281
return isinstance(obj, bytes)
12382

@@ -130,23 +89,14 @@ def is_string(obj):
13089

13190
def is_unicode(obj):
13291
"""Return True if `obj` is unicode"""
133-
if PY2:
134-
# Python 2
135-
return isinstance(obj, unicode)
136-
else:
92+
if True:
13793
# Python 3
13894
return isinstance(obj, str)
13995

14096

14197
def to_text_string(obj, encoding=None):
14298
"""Convert `obj` to (unicode) text string"""
143-
if PY2:
144-
# Python 2
145-
if encoding is None:
146-
return unicode(obj)
147-
else:
148-
return unicode(obj, encoding)
149-
else:
99+
if True:
150100
# Python 3
151101
if encoding is None:
152102
return str(obj)
@@ -159,13 +109,7 @@ def to_text_string(obj, encoding=None):
159109

160110
def to_binary_string(obj, encoding=None):
161111
"""Convert `obj` to binary string (bytes in Python 3, str in Python 2)"""
162-
if PY2:
163-
# Python 2
164-
if encoding is None:
165-
return str(obj)
166-
else:
167-
return obj.encode(encoding)
168-
else:
112+
if True:
169113
# Python 3
170114
return bytes(
171115
obj, 'utf-8' if encoding is None else encoding
@@ -177,30 +121,21 @@ def to_binary_string(obj, encoding=None):
177121
# ==============================================================================
178122
def get_func_code(func):
179123
"""Return function code object"""
180-
if PY2:
181-
# Python 2
182-
return func.func_code
183-
else:
124+
if True:
184125
# Python 3
185126
return func.__code__
186127

187128

188129
def get_func_name(func):
189130
"""Return function name"""
190-
if PY2:
191-
# Python 2
192-
return func.func_name
193-
else:
131+
if True:
194132
# Python 3
195133
return func.__name__
196134

197135

198136
def get_func_defaults(func):
199137
"""Return function default argument values"""
200-
if PY2:
201-
# Python 2
202-
return func.func_defaults
203-
else:
138+
if True:
204139
# Python 3
205140
return func.__defaults__
206141

@@ -210,47 +145,29 @@ def get_func_defaults(func):
210145
# ==============================================================================
211146
def get_meth_func(obj):
212147
"""Return method function object"""
213-
if PY2:
214-
# Python 2
215-
return obj.im_func
216-
else:
148+
if True:
217149
# Python 3
218150
return obj.__func__
219151

220152

221153
def get_meth_class_inst(obj):
222154
"""Return method class instance"""
223-
if PY2:
224-
# Python 2
225-
return obj.im_self
226-
else:
155+
if True:
227156
# Python 3
228157
return obj.__self__
229158

230159

231160
def get_meth_class(obj):
232161
"""Return method class"""
233-
if PY2:
234-
# Python 2
235-
return obj.im_class
236-
else:
162+
if True:
237163
# Python 3
238164
return obj.__self__.__class__
239165

240166

241167
# ==============================================================================
242168
# Misc.
243169
# ==============================================================================
244-
if PY2:
245-
# Python 2
246-
input = raw_input
247-
getcwd = os.getcwdu
248-
cmp = cmp
249-
import string
250-
251-
str_lower = string.lower
252-
from itertools import izip_longest as zip_longest
253-
else:
170+
if True:
254171
# Python 3
255172
input = input
256173
getcwd = os.getcwd

winpython/qthelpers.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353

5454
# Local import
5555
from winpython import config
56-
from winpython.py3compat import (
57-
is_text_string,
58-
to_text_string,
59-
)
56+
#from winpython.py3compat import (
57+
# is_text_string,
58+
# to_text_string,
59+
#)
6060

6161

6262
def get_icon(name):
@@ -157,11 +157,13 @@ def mimedata2url(source, extlist=None):
157157
pathlist = []
158158
if source.hasUrls():
159159
for url in source.urls():
160-
path = _process_mime_path(to_text_string(url.toString()), extlist)
160+
# path = _process_mime_path(to_text_string(url.toString()), extlist)
161+
path = _process_mime_path(str(url.toString()), extlist)
161162
if path is not None:
162163
pathlist.append(path)
163164
elif source.hasText():
164-
for rawpath in to_text_string(source.text()).splitlines():
165+
# for rawpath in to_text_string(source.text()).splitlines():
166+
for rawpath in str(source.text()).splitlines():
165167
path = _process_mime_path(rawpath, extlist)
166168
if path is not None:
167169
pathlist.append(path)
@@ -216,7 +218,8 @@ def create_action(
216218
action.toggled.connect(toggled)
217219
action.setCheckable(True)
218220
if icon is not None:
219-
if is_text_string(icon):
221+
# if is_text_string(icon):
222+
if isinstance(obj, str)
220223
icon = get_icon(icon)
221224
action.setIcon(icon)
222225
if shortcut is not None:

winpython/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
import io
2828

2929
# Local imports
30-
from winpython.py3compat import winreg
30+
#from winpython.py3compat import winreg
31+
import winreg
3132

3233
def get_python_executable(path = None):
3334
"""return the python executable"""

winpython/wppm.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@
2222
# Local imports
2323
from winpython import utils
2424
from winpython.config import DATA_PATH
25-
from winpython.py3compat import configparser as cp
25+
# from winpython.py3compat import configparser as cp
26+
import configparser as cp
2627

2728
# from former wppm separate script launcher
2829
import textwrap
2930
from argparse import ArgumentParser, HelpFormatter, RawTextHelpFormatter
3031

31-
# from winpython import py3compat
32-
3332
from winpython import piptree
3433

35-
# import information reader
34+
# import information reader
3635
# importlib_metadata before Python 3.8
3736
try:
3837
from importlib import metadata as metadata # Python-3.8

0 commit comments

Comments
 (0)
0