Skip to content

Commit 8a3770e

Browse files
committed
flake8 convert type comparisons to isinstance.
Also define unicode type for python3. Move _marker to top of file similar to rdbms_common.py.
1 parent 0e67976 commit 8a3770e

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

roundup/backends/back_anydbm.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ def db_exists(config):
6262
def db_nuke(config):
6363
shutil.rmtree(config.DATABASE)
6464

65+
66+
# python 3 doesn't have a unicode type
67+
try:
68+
unicode # noqa: F821
69+
except NameError:
70+
unicode = str
71+
72+
73+
# marker used for an unspecified keyword argument
74+
_marker = []
75+
76+
6577
#
6678
# Now the database
6779
#
@@ -820,9 +832,6 @@ def close(self):
820832
self.lockfile = None
821833

822834

823-
_marker = []
824-
825-
826835
class Class(hyperdb.Class):
827836
"""The handle to a particular class of nodes in a hyperdatabase."""
828837

@@ -1321,7 +1330,7 @@ def set_inner(self, nodeid, **propvalues):
13211330
journalvalues[propname] = tuple(l)
13221331

13231332
elif isinstance(prop, hyperdb.String):
1324-
if value is not None and type(value) != type('') and type(value) != type(u''):
1333+
if value is not None and not isinstance(value, (str, unicode)):
13251334
raise TypeError('new property "%s" not a '
13261335
'string' % propname)
13271336
if prop.indexme:
@@ -1569,7 +1578,7 @@ def find(self, **propspec):
15691578
if self.db.RETIRED_FLAG in item:
15701579
continue
15711580
for propname, itemids in propspec.items():
1572-
if type(itemids) is not type({}):
1581+
if not isinstance(itemids, dict):
15731582
if itemids is None or isinstance(itemids, type("")):
15741583
itemids = {itemids: 1}
15751584
else:
@@ -1750,7 +1759,7 @@ def _filter(self, search_matches, filterspec, proptree,
17501759
for k, v in filtertype.items():
17511760
propclass = props[k]
17521761
if isinstance(propclass, hyperdb.Link):
1753-
if type(v) is not type([]):
1762+
if not isinstance(v, list):
17541763
v = [v]
17551764
l.append((LINK, k, v))
17561765
elif isinstance(propclass, hyperdb.Multilink):
@@ -1762,11 +1771,11 @@ def _filter(self, search_matches, filterspec, proptree,
17621771
# the value -1 is a special "not set" sentinel
17631772
if v in ('-1', ['-1']):
17641773
v = []
1765-
elif type(v) is not type([]):
1774+
elif not isinstance(v, list):
17661775
v = [v]
17671776
l.append((MULTILINK, k, v))
17681777
elif isinstance(propclass, hyperdb.String) and k != 'id':
1769-
if type(v) is not type([]):
1778+
if not isinstance(v, list):
17701779
v = [v]
17711780
for x in v:
17721781
if exact:
@@ -1799,33 +1808,33 @@ def _filter(self, search_matches, filterspec, proptree,
17991808
pass
18001809

18011810
elif isinstance(propclass, hyperdb.Boolean):
1802-
if type(v) == type(""):
1811+
if isinstance(v, str):
18031812
v = v.split(',')
1804-
if type(v) != type([]):
1813+
if not isinstance(v, list):
18051814
v = [v]
18061815
bv = []
18071816
for val in v:
1808-
if type(val) is type(''):
1817+
if isinstance(val, str):
18091818
bv.append(propclass.from_raw(val))
18101819
else:
18111820
bv.append(val)
18121821
l.append((OTHER, k, bv))
18131822

18141823
elif k == 'id':
1815-
if type(v) != type([]):
1824+
if not isinstance(v, list):
18161825
v = v.split(',')
18171826
l.append((OTHER, k, [str(int(val)) for val in v]))
18181827

18191828
elif isinstance(propclass, hyperdb.Number):
1820-
if type(v) != type([]):
1829+
if not isinstance(v, list):
18211830
try:
18221831
v = v.split(',')
18231832
except AttributeError:
18241833
v = [v]
18251834
l.append((OTHER, k, [float(val) for val in v]))
18261835

18271836
elif isinstance(propclass, hyperdb.Integer):
1828-
if type(v) != type([]):
1837+
if not isinstance(v, list):
18291838
try:
18301839
v = v.split(',')
18311840
except AttributeError:

0 commit comments

Comments
 (0)