Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more redundant internal compatibility aliases #366

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions boltons/deprutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@


import sys
from types import ModuleType
from warnings import warn

ModuleType = type(sys)

# todo: only warn once


Expand Down
16 changes: 7 additions & 9 deletions boltons/funcutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
import functools
import itertools
from inspect import formatannotation
from types import MethodType, FunctionType

make_method = lambda desc, obj, obj_type: MethodType(desc, obj)
from types import FunctionType, MethodType

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

try:
from .typeutils import make_sentinel
Expand Down Expand Up @@ -252,7 +253,7 @@ def _partialmethod(self):
return functools.partialmethod(self.func, *self.args, **self.keywords)

def __get__(self, obj, obj_type):
return make_method(self, obj, obj_type)
return MethodType(self, obj)



Expand Down Expand Up @@ -283,13 +284,13 @@ def __get__(self, obj, obj_type):
name = self.__name__

if obj is None:
return make_method(self, obj, obj_type)
return MethodType(self, obj)
try:
# since this is a data descriptor, this block
# is probably only hit once (per object)
return obj.__dict__[name]
except KeyError:
obj.__dict__[name] = ret = make_method(self, obj, obj_type)
obj.__dict__[name] = ret = MethodType(self, obj)
return ret


Expand Down Expand Up @@ -971,9 +972,6 @@ def _indent(text, margin, newline='\n', key=bool):
return newline.join(indented_lines)


from functools import total_ordering


def noop(*args, **kwargs):
"""
Simple function that should be used when no effect is desired.
Expand Down
15 changes: 3 additions & 12 deletions boltons/mathutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ def floor(x, options=None):
return options[i - 1]


try:
_int_types = (int, long)
bytes = str
except NameError:
# py3 has no long
_int_types = (int,)
unicode = str


class Bits:
'''
An immutable bit-string or bit-array object.
Expand All @@ -147,12 +138,12 @@ class Bits:
__slots__ = ('val', 'len')

def __init__(self, val=0, len_=None):
if type(val) not in _int_types:
if type(val) is not int:
if type(val) is list:
val = ''.join(['1' if e else '0' for e in val])
if type(val) is bytes:
val = val.decode('ascii')
if type(val) is unicode:
if type(val) is str:
if len_ is None:
len_ = len(val)
if val.startswith('0x'):
Expand All @@ -164,7 +155,7 @@ def __init__(self, val=0, len_=None):
val = int(val, 2)
else:
val = 0
if type(val) not in _int_types:
if type(val) is not int:
raise TypeError(f'initialized with bad type: {type(val).__name__}')
if val < 0:
raise ValueError('Bits cannot represent negative values')
Expand Down
7 changes: 3 additions & 4 deletions boltons/timeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@
from datetime import tzinfo, timedelta, date, datetime


def total_seconds(td):
# For legacy compatibility.
# boltons used to offer an implementation of total_seconds for Python <2.7
return timedelta.total_seconds(td)
# For legacy compatibility.
# boltons used to offer an implementation of total_seconds for Python <2.7
total_seconds = timedelta.total_seconds


def dt_to_timestamp(dt):
Expand Down
14 changes: 6 additions & 8 deletions boltons/urlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
import string
from unicodedata import normalize

unicode = str

# The unreserved URI characters (per RFC 3986 Section 2.3)
_UNRESERVED_CHARS = frozenset('~-._0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'abcdefghijklmnopqrstuvwxyz')
Expand Down Expand Up @@ -124,9 +122,9 @@ class URLParseError(ValueError):

def to_unicode(obj):
try:
return unicode(obj)
return str(obj)
except UnicodeDecodeError:
return unicode(obj, encoding=DEFAULT_ENCODING)
return str(obj, encoding=DEFAULT_ENCODING)


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

def _add_text(t):
if ret and isinstance(ret[-1], unicode):
if ret and isinstance(ret[-1], str):
ret[-1] += t
else:
_add(t)
Expand Down Expand Up @@ -311,7 +309,7 @@ def unquote_to_bytes(string):
# Is it a string-like object?
string.split
return b''
if isinstance(string, unicode):
if isinstance(string, str):
string = string.encode('utf-8')
bits = string.split(b'%')
if len(bits) == 1:
Expand Down Expand Up @@ -741,7 +739,7 @@ def get_authority(self, full_quote=False, with_userinfo=False):
# TODO: 0 port?
if self.port and self.port != self.default_port:
_add(':')
_add(unicode(self.port))
_add(str(self.port))
return ''.join(parts)

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