8000 Rename is_text and is_bytes to istext and isbytes · thecodingchicken/python-future@8236d76 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8236d76

Browse files
committed
Rename is_text and is_bytes to istext and isbytes
1 parent 2100e47 commit 8236d76

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

docs/source/isinstance.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,29 @@ On Python 2, (unicode) string literals ``'...'`` and byte-string literals
3939
the native Py2 unicode and 8-bit string types).
4040

4141
If type-checking is necessary to distinguish unicode text from bytes
42-
portably across Py3 and Py2, utility functions called :func:`is_text` and
43-
:func:`is_bytes` are available in :mod:`future.utils`. You can use them
42+
portably across Py3 and Py2, utility functions called :func:`istext` and
43+
:func:`isbytes` are available in :mod:`future.utils`. You can use them
4444
as follows::
4545

4646
>>> from __future__ import unicode_literals
4747
>>> from future.builtins import *
48-
>>> from future.utils import is_text, is_bytes
48+
>>> from future.utils import istext, isbytes
4949

50-
>>> assert is_text('My (unicode) string')
51-
>>> assert is_text(str('My (unicode) string'))
50+
>>> assert istext('My (unicode) string')
51+
>>> assert istext(str('My (unicode) string'))
5252

53-
>>> assert is_bytes(b'My byte-string')
54-
>>> assert is_bytes(bytes(b'My byte-string'))
53+
>>> assert isbytes(b'My byte-string')
54+
>>> assert isbytes(bytes(b'My byte-string'))
5555

56-
``is_text(s)`` tests whether the object ``s`` is (or inherits from) a
56+
``istext(s)`` tests whether the object ``s`` is (or inherits from) a
5757
unicode string. It is equivalent to the following expression::
5858

5959
isinstance(s, type(u''))
6060

6161
which is ``True`` if ``s`` is a native Py3 string, Py2 unicode object, or
6262
:class:`future.builtins.str` object on Py2.
6363

64-
Likewise, ``is_bytes(b)`` tests whether ``b`` is (or inherits from) an
64+
Likewise, ``isbytes(b)`` tests whether ``b`` is (or inherits from) an
6565
8-bit byte-string. It is equivalent to::
6666

6767
isinstance(b, type(b''))

future/builtins/backports/newbytes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"""
1919

2020
from collections import Iterable
21-
from numbers import Integral
21+
from numbers import Number, Integral
2222

23-
from future.utils import PY3, is_text, is_bytes
23+
from future.utils import PY3, istext, isbytes
2424
from future.builtins.backports import no, issubset
2525

2626

@@ -115,10 +115,10 @@ def __rmul__(self, other):
115115

116116
def join(self, iterable_of_bytes):
117117
errmsg = 'sequence item {}: expected bytes, {} found'
118-
if is_bytes(iterable_of_bytes) or is_text(iterable_of_bytes):
118+
if isbytes(iterable_of_bytes) or istext(iterable_of_bytes):
119119
raise TypeError(errmsg.format(0, type(iterable_of_bytes)))
120120
for i, item in enumerate(iterable_of_bytes):
121-
if is_text(item):
121+
if istext(item):
122122
raise TypeError(errmsg.format(i, type(item)))
123123
return newbytes(super(newbytes, self).join(iterable_of_bytes))
124124

@@ -230,22 +230,22 @@ def __ne__(self, other):
230230
unorderable_err = 'unorderable types: bytes() and {}'
231231

232232
def __lt__(self, other):
233-
if is_text(other) or isinstance(other, Integral):
233+
if istext(other) or isinstance(other, Number):
234234
raise TypeError(self.unorderable_err.format(type(other)))
235235
return super(newbytes, self).__lt__(other)
236236

237237
def __le__(self, other):
238-
if is_text(other) or isinstance(other, Integral):
238+
if istext(other) or isinstance(other, Integral):
239239
raise TypeError(self.unorderable_err.format(type(other)))
240240
return super(newbytes, self).__le__(other)
241241

242242
def __gt__(self, other):
243-
if is_text(other) or isinstance(other, Integral):
243+
if istext(other) or isinstance(other, Integral):
244244
raise TypeError(self.unorderable_err.format(type(other)))
245245
return super(newbytes, self).__gt__(other)
246246

247247
def __ge__(self, other):
248-
if is_text(other) or isinstance(other, Integral):
248+
if istext(other) or isinstance(other, Integral):
249249
raise TypeError(self.unorderable_err.format(type(other)))
250250
return super(newbytes, self).__ge__(other)
251251

future/tests/test_utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ def setUp(self):
1919
self.b = b'ABCDEFG'
2020
self.b2 = bytes(self.b)
2121

22-
def test_is_text(self):
23-
self.assertTrue(utils.is_text(self.s))
24-
self.assertTrue(utils.is_text(self.s2))
25-
self.assertFalse(utils.is_text(self.b))
26-
self.assertFalse(utils.is_text(self.b2))
27-
28-
def test_is_bytes(self):
29-
self.assertTrue(utils.is_bytes(self.b))
30-
self.assertTrue(utils.is_bytes(self.b2))
31-
self.assertFalse(utils.is_bytes(self.s))
32-
self.assertFalse(utils.is_bytes(self.s2))
22+
def test_istext(self):
23+
self.assertTrue(utils.istext(self.s))
24+
self.assertTrue(utils.istext(self.s2))
25+
self.assertFalse(utils.istext(self.b))
26+
self.assertFalse(utils.istext(self.b2))
27+
28+
def test_isbytes(self):
29+
self.assertTrue(utils.isbytes(self.b))
30+
self.assertTrue(utils.isbytes(self.b2))
31+
self.assertFalse(utils.isbytes(self.s))
32+
self.assertFalse(utils.isbytes(self.s2))
3333

3434

3535
if __name__ == '__main__':

future/utils/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,15 @@ def is_new_style(cls):
376376
# ``from future.builtins import *``.
377377
native_str = str
378378

379-
def is_text(obj):
379+
def istext(obj):
380380
return isinstance(obj, type(u''))
381381

382382

383-
def is_bytes(obj):
383+
def isbytes(obj):
384384
return isinstance(obj, type(b''))
385385

386386

387-
# def is_int(obj):
387+
# def isint(obj):
388388
# """
389389
# Don't define this. Use this idiom instead:
390390
# isinstance(obj, numbers.Integral)

0 commit comments

Comments
 (0)
0