Skip to content

Commit 9381c52

Browse files
Avasammahmoud
authored andcommitted
Remove more redundant internal compatibility aliases
1 parent 827f193 commit 9381c52

File tree

5 files changed

+20
-35
lines changed

5 files changed

+20
-35
lines changed

boltons/deprutils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030

3131

3232
import sys
33+
from types import ModuleType
3334
from warnings import warn
3435

35-
ModuleType = type(sys)
36-
3736
# todo: only warn once
3837

3938

boltons/funcutils.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
import functools
4141
import itertools
4242
from inspect import formatannotation
43-
from types import MethodType, FunctionType
44-
45-
make_method = lambda desc, obj, obj_type: MethodType(desc, obj)
43+
from types import FunctionType, MethodType
4644

45+
# For legacy compatibility.
46+
# boltons used to offer an implementation of total_ordering for Python <2.7
47+
from functools import total_ordering as total_ordering
4748

4849
try:
4950
from .typeutils import make_sentinel
@@ -257,7 +258,7 @@ def __partialmethod__(self):
257258
return functools.partialmethod(self.func, *self.args, **self.keywords)
258259

259260
def __get__(self, obj, obj_type):
260-
return make_method(self, obj, obj_type)
261+
return MethodType(self, obj)
261262

262263

263264

@@ -293,13 +294,13 @@ def __get__(self, obj, obj_type):
293294
name = self.__name__
294295

295296
if obj is None:
296-
return make_method(self, obj, obj_type)
297+
return MethodType(self, obj)
297298
try:
298299
# since this is a data descriptor, this block
299300
# is probably only hit once (per object)
300301
return obj.__dict__[name]
301302
except KeyError:
302-
obj.__dict__[name] = ret = make_method(self, obj, obj_type)
303+
obj.__dict__[name] = ret = MethodType(self, obj)
303304
return ret
304305

305306

@@ -981,9 +982,6 @@ def _indent(text, margin, newline='\n', key=bool):
981982
return newline.join(indented_lines)
982983

983984

984-
from functools import total_ordering
985-
986-
987985
def noop(*args, **kwargs):
988986
"""
989987
Simple function that should be used when no effect is desired.

boltons/mathutils.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,6 @@ def floor(x, options=None):
121121
return options[i - 1]
122122

123123

124-
try:
125-
_int_types = (int, long)
126-
bytes = str
127-
except NameError:
128-
# py3 has no long
129-
_int_types = (int,)
130-
unicode = str
131-
132-
133124
class Bits:
134125
'''
135126
An immutable bit-string or bit-array object.
@@ -147,12 +138,12 @@ class Bits:
147138
__slots__ = ('val', 'len')
148139

149140
def __init__(self, val=0, len_=None):
150-
if type(val) not in _int_types:
141+
if type(val) is not int:
151142
if type(val) is list:
152143
val = ''.join(['1' if e else '0' for e in val])
153144
if type(val) is bytes:
154145
val = val.decode('ascii')
155-
if type(val) is unicode:
146+
if type(val) is str:
156147
if len_ is None:
157148
len_ = len(val)
158149
if val.startswith('0x'):
@@ -164,7 +155,7 @@ def __init__(self, val=0, len_=None):
164155
val = int(val, 2)
165156
else:
166157
val = 0
167-
if type(val) not in _int_types:
158+
if type(val) is not int:
168159
raise TypeError(f'initialized with bad type: {type(val).__name__}')
169160
if val < 0:
170161
raise ValueError('Bits cannot represent negative values')

boltons/timeutils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@
5757
from datetime import tzinfo, timedelta, date, datetime, timezone
5858

5959

60-
def total_seconds(td):
61-
# For legacy compatibility.
62-
# boltons used to offer an implementation of total_seconds for Python <2.7
63-
return timedelta.total_seconds(td)
60+
# For legacy compatibility.
61+
# boltons used to offer an implementation of total_seconds for Python <2.7
62+
total_seconds = timedelta.total_seconds
6463

6564

6665
def dt_to_timestamp(dt):

boltons/urlutils.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555
import string
5656
from unicodedata import normalize
5757

58-
unicode = str
59-
6058
# The unreserved URI characters (per RFC 3986 Section 2.3)
6159
_UNRESERVED_CHARS = frozenset('~-._0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
6260
'abcdefghijklmnopqrstuvwxyz')
@@ -124,9 +122,9 @@ class URLParseError(ValueError):
124122

125123
def to_unicode(obj):
126124
try:
127-
return unicode(obj)
125+
return str(obj)
128126
except UnicodeDecodeError:
129-
return unicode(obj, encoding=DEFAULT_ENCODING)
127+
return str(obj, encoding=DEFAULT_ENCODING)
130128

131129

132130
# regex from gruber via tornado
@@ -174,7 +172,7 @@ def find_all_links(text, with_text=False, default_scheme='https', schemes=()):
174172
_add = ret.append
175173

176174
def _add_text(t):
177-
if ret and isinstance(ret[-1], unicode):
175+
if ret and isinstance(ret[-1], str):
178176
ret[-1] += t
179177
else:
180178
_add(t)
@@ -311,7 +309,7 @@ def unquote_to_bytes(string):
311309
# Is it a string-like object?
312310
string.split
313311
return b''
314-
if isinstance(string, unicode):
312+
if isinstance(string, str):
315313
string = string.encode('utf-8')
316314
bits = string.split(b'%')
317315
if len(bits) == 1:
@@ -741,7 +739,7 @@ def get_authority(self, full_quote=False, with_userinfo=False):
741739
# TODO: 0 port?
742740
if self.port and self.port != self.default_port:
743741
_add(':')
744-
_add(unicode(self.port))
742+
_add(str(self.port))
745743
return ''.join(parts)
746744

747745
def to_text(self, full_quote=False):
@@ -903,7 +901,7 @@ def parse_url(url_text):
903901
>>> sorted(res.keys()) # res is a basic dictionary
904902
['_netloc_sep', 'authority', 'family', 'fragment', 'host', 'password', 'path', 'port', 'query', 'scheme', 'username']
905903
"""
906-
url_text = unicode(url_text)
904+
url_text = str(url_text)
907905
# raise TypeError('parse_url expected text, not %r' % url_str)
908906
um = _URL_RE.match(url_text)
909907
try:

0 commit comments

Comments
 (0)