Skip to content

Commit 44689e5

Browse files
committed
Use functions rather than special methods, e.g. type(f) instead of f.__class__
1 parent dfae3b2 commit 44689e5

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,13 @@ v0.10.0
7676

7777
{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}
7878

79+
- Added `next` shortcut to `OrderBy` returned from `BoundColumn.order_by_alias`
7980
- Added `OrderByTuple.get()`
8081
- Deprecated `BoundColumn.sortable`, `Column.sortable`, `Table.sortable`,
8182
`sortable` CSS class, `BoundColumns.itersortable`, `BoundColumns.sortable`; use `orderable` instead of
8283
`sortable`.
8384
- Added `BoundColumn.is_ordered`
84-
- Added `next` shortcut to `OrderBy` returned from `BoundColumn.order_by_alias`
8585
- Introduced concept of an `order by alias`, see glossary in the docs for details.
86-
-
87-
88-
89-
note use type() unicode() str() etc, rather than special methods __foo__
9086

9187
v0.9.6
9288
------

django_tables2/columns.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, verbose_name=None, accessor=None, default=None,
7272
if not (accessor is None or isinstance(accessor, basestring) or
7373
callable(accessor)):
7474
raise TypeError('accessor must be a string or callable, not %s' %
75-
accessor.__class__.__name__)
75+
type(accessor).__name__)
7676
if callable(accessor) and default is not None:
7777
raise TypeError('accessor must be string when default is used, not callable')
7878
self.accessor = A(accessor) if accessor else None
@@ -89,7 +89,7 @@ def __init__(self, verbose_name=None, accessor=None, default=None,
8989
attrs = attrs or {}
9090
if not isinstance(attrs, Attrs):
9191
warnings.warn('attrs must be Attrs object, not %s'
92-
% attrs.__class__.__name__, DeprecationWarning)
92+
% type(attrs).__name__, DeprecationWarning)
9393
attrs = Attrs(attrs)
9494
self.attrs = attrs
9595
# massage order_by into an OrderByTuple or None
@@ -193,7 +193,7 @@ def __init__(self, attrs=None, **extra):
193193
attrs = attrs or Attrs()
194194
if not isinstance(attrs, Attrs):
195195
warnings.warn('attrs must be Attrs object, not %s'
196-
% attrs.__class__.__name__, DeprecationWarning)
196+
% type(attrs).__name__, DeprecationWarning)
197197
attrs = Attrs(td__input=attrs)
198198
# This is done for backwards compatible too, there used to be a
199199
# ``header_attrs`` argument, but this has been deprecated. We'll
@@ -281,7 +281,7 @@ def __init__(self, viewname, urlconf=None, args=None, kwargs=None,
281281
attrs = attrs or Attrs()
282282
if not isinstance(attrs, Attrs):
283283
warnings.warn('attrs must be Attrs object, not %s'
284-
% attrs.__class__.__name__, DeprecationWarning)
284+
% type(attrs).__name__, DeprecationWarning)
285285
attrs = Attrs(a=attrs)
286286
extra['attrs'] = attrs
287287
super(LinkColumn, self).__init__(**extra)
@@ -791,4 +791,4 @@ def __getitem__(self, index):
791791
"choices are: %s" % (index, self.names()))
792792
else:
793793
raise TypeError(u'row indices must be integers or str, not %s'
794-
% index.__class__.__name__)
794+
% type(index).__name__)

django_tables2/tables.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, data, table):
4040
except:
4141
raise ValueError('data must be QuerySet-like (have count and '
4242
'order_by) or support list(data) -- %s is '
43-
'neither' % data.__class__.__name__)
43+
'neither' % type(data).__name__)
4444

4545
def __len__(self):
4646
# Use the queryset count() method to get the length, instead of
@@ -79,8 +79,7 @@ def __iter__(self):
7979
with indexing into querysets, so this side-steps that problem (as well
8080
as just being a better way to iterate).
8181
"""
82-
return (self.list.__iter__() if hasattr(self, 'list')
83-
else self.queryset.__iter__())
82+
return iter(self.list) if hasattr(self, 'list') else iter(self.queryset)
8483

8584
def __getitem__(self, index):
8685
"""Forwards indexing accesses to underlying data"""
@@ -245,7 +244,7 @@ def __init__(self, data, order_by=None, orderable=None, empty_text=None,
245244
# Make a copy so that modifying this will not touch the class
246245
# definition. Note that this is different from forms, where the
247246
# copy is made available in a ``fields`` attribute.
248-
self.base_columns = copy.deepcopy(self.__class__.base_columns)
247+
self.base_columns = copy.deepcopy(type(self).base_columns)
249248
self.exclude = exclude or ()
250249
self.sequence = sequence
251250
# `None` value for order_by means no order is specified. This means we

django_tables2/utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from __future__ import absolute_import, unicode_literals
23
from django.template import Context
34
from django.utils.datastructures import SortedDict
45
from django.utils.html import escape
@@ -32,14 +33,14 @@ def expand(self, columns):
3233
# Check for columns in the sequence that don't exist in *columns*
3334
extra = (set(self) - set(("...", ))).difference(columns)
3435
if extra:
35-
raise ValueError(u"sequence contains columns that do not exist"
36-
u" in the table. Remove '%s'."
36+
raise ValueError("sequence contains columns that do not exist"
37+
" in the table. Remove '%s'."
3738
% "', '".join(extra))
3839
else:
3940
diff = set(self) ^ set(columns)
4041
if diff:
41-
raise ValueError(u"sequence does not match columns. Fix '%s' "
42-
u"or possibly add '...'." % "', '".join(diff))
42+
raise ValueError("sequence does not match columns. Fix '%s' "
43+
"or possibly add '...'." % "', '".join(diff))
4344
# everything looks good, let's expand the "..." item
4445
columns = columns[:] # don't modify
4546
head = []
@@ -206,8 +207,8 @@ def _cmp(a, b):
206207
try:
207208
res = cmp(x, y)
208209
except TypeError:
209-
res = cmp((repr(x.__class__), id(x.__class__), x),
210-
(repr(y.__class__), id(y.__class__), y))
210+
res = cmp((repr(type(x)), id(type(x)), x),
211+
(repr(type(y)), id(type(y)), y))
211212
if res != 0:
212213
return -res if reverse else res
213214
return 0
@@ -343,7 +344,7 @@ def as_html(self):
343344
:rtype: :class:`~django.utils.safestring.SafeUnicode` object
344345
345346
"""
346-
return mark_safe(' '.join([u'%s="%s"' % (k, escape(v))
347+
return mark_safe(' '.join(['%s="%s"' % (k, escape(v))
347348
for k, v in self.iteritems()]))
348349

349350

django_tables2/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_table_class(self):
4545
return self.table_class
4646
raise ImproperlyConfigured(u"A table class was not specified. Define "
4747
u"%(cls)s.table_class"
48-
% {"cls": self.__class__.__name__})
48+
% {"cls": type(self).__name__})
4949

5050
def get_context_table_name(self, table):
5151
"""
@@ -63,7 +63,7 @@ def get_table_data(self):
6363
return self.get_queryset()
6464
raise ImproperlyConfigured(u"Table data was not specified. Define "
6565
u"%(cls)s.table_data"
66-
% {"cls": self.__class__.__name__})
66+
% {"cls": type(self).__name__})
6767

6868
def get_context_data(self, **kwargs):
6969
"""

0 commit comments

Comments
 (0)