Skip to content

Commit f092459

Browse files
Graham Higginsmwatts15
authored andcommitted
Adding flake8 lint checker to tox configuration
- Removing uses of bare except: Some handlers are unnecessary (whatever is thrown should be)
1 parent abe2088 commit f092459

File tree

10 files changed

+46
-59
lines changed

10 files changed

+46
-59
lines changed

rdflib_sqlalchemy/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ def registerplugins():
4444
from rdflib import plugin
4545

4646
try:
47-
x = plugin.get("SQLAlchemy", Store)
48-
del x
49-
return # plugins already registered
50-
except:
51-
pass # must register plugins
47+
plugin.get("SQLAlchemy", Store)
48+
except plugin.PluginException:
49+
pass
5250

5351
# Register the plugins ...
5452

rdflib_sqlalchemy/constants.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@
1717
INTERNED_PREFIX = "kb_"
1818

1919
TERM_COMBINATIONS = dict([(term, index) for index, term in enumerate([
20-
"UUUU", "UUUB", "UUUF", "UUVU", "UUVB", "UUVF", "UUBU", "UUBB", "UUBF",
21-
"UULU", "UULB", "UULF", "UUFU", "UUFB", "UUFF",
22-
#
23-
"UVUU", "UVUB", "UVUF", "UVVU", "UVVB", "UVVF", "UVBU", "UVBB", "UVBF",
24-
"UVLU", "UVLB", "UVLF", "UVFU", "UVFB", "UVFF",
25-
#
26-
"VUUU", "VUUB", "VUUF", "VUVU", "VUVB", "VUVF", "VUBU", "VUBB", "VUBF",
27-
"VULU", "VULB", "VULF", "VUFU", "VUFB", "VUFF",
28-
#
29-
"VVUU", "VVUB", "VVUF", "VVVU", "VVVB", "VVVF", "VVBU", "VVBB", "VVBF",
30-
"VVLU", "VVLB", "VVLF", "VVFU", "VVFB", "VVFF",
31-
#
32-
"BUUU", "BUUB", "BUUF", "BUVU", "BUVB", "BUVF", "BUBU", "BUBB", "BUBF",
33-
"BULU", "BULB", "BULF", "BUFU", "BUFB", "BUFF",
34-
#
35-
"BVUU", "BVUB", "BVUF", "BVVU", "BVVB", "BVVF", "BVBU", "BVBB", "BVBF",
36-
"BVLU", "BVLB", "BVLF", "BVFU", "BVFB", "BVFF",
37-
#
38-
"FUUU", "FUUB", "FUUF", "FUVU", "FUVB", "FUVF", "FUBU", "FUBB", "FUBF",
39-
"FULU", "FULB", "FULF", "FUFU", "FUFB", "FUFF",
40-
#
41-
"FVUU", "FVUB", "FVUF", "FVVU", "FVVB", "FVVF", "FVBU", "FVBB", "FVBF",
42-
"FVLU", "FVLB", "FVLF", "FVFU", "FVFB", "FVFF",
20+
"UUUU", "UUUB", "UUUF", "UUVU", "UUVB", "UUVF", "UUBU", "UUBB", "UUBF",
21+
"UULU", "UULB", "UULF", "UUFU", "UUFB", "UUFF",
22+
#
23+
"UVUU", "UVUB", "UVUF", "UVVU", "UVVB", "UVVF", "UVBU", "UVBB", "UVBF",
24+
"UVLU", "UVLB", "UVLF", "UVFU", "UVFB", "UVFF",
25+
#
26+
"VUUU", "VUUB", "VUUF", "VUVU", "VUVB", "VUVF", "VUBU", "VUBB", "VUBF",
27+
"VULU", "VULB", "VULF", "VUFU", "VUFB", "VUFF",
28+
#
29+
"VVUU", "VVUB", "VVUF", "VVVU", "VVVB", "VVVF", "VVBU", "VVBB", "VVBF",
30+
"VVLU", "VVLB", "VVLF", "VVFU", "VVFB", "VVFF",
31+
#
32+
"BUUU", "BUUB", "BUUF", "BUVU", "BUVB", "BUVF", "BUBU", "BUBB", "BUBF",
33+
"BULU", "BULB", "BULF", "BUFU", "BUFB", "BUFF",
34+
#
35+
"BVUU", "BVUB", "BVUF", "BVVU", "BVVB", "BVVF", "BVBU", "BVBB", "BVBF",
36+
"BVLU", "BVLB", "BVLF", "BVFU", "BVFB", "BVFF",
37+
#
38+
"FUUU", "FUUB", "FUUF", "FUVU", "FUVB", "FUVF", "FUBU", "FUBB", "FUBF",
39+
"FULU", "FULB", "FULF", "FUFU", "FUFB", "FUFF",
40+
#
41+
"FVUU", "FVUB", "FVUF", "FVVU", "FVVB", "FVVF", "FVBU", "FVBB", "FVBF",
42+
"FVLU", "FVLB", "FVLF", "FVFU", "FVFB", "FVFF",
4343
])])
4444

4545
REVERSE_TERM_COMBINATIONS = dict([

rdflib_sqlalchemy/store.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,8 @@ def contexts(self, triple=None):
562562
# partition (optionally)
563563
selects = []
564564
if (not self.STRONGLY_TYPED_TERMS or
565-
isinstance(obj, Literal) or
566-
not obj
567-
or (self.STRONGLY_TYPED_TERMS and isinstance(obj, REGEXTerm))):
565+
isinstance(obj, Literal) or not obj or (
566+
self.STRONGLY_TYPED_TERMS and isinstance(obj, REGEXTerm))):
568567
clause = self.build_clause(literal, subject, predicate, obj)
569568
selects.append(
570569
(literal, clause, ASSERTED_LITERAL_PARTITION))
@@ -674,7 +673,8 @@ def namespace(self, prefix):
674673
rt = [rtTuple[0] for rtTuple in res.fetchall()]
675674
res.close()
676675
return rt and URIRef(rt[0]) or None
677-
except:
676+
except Exception:
677+
_logger.warning('exception in namespace retrieval', exc_info=True)
678678
return None
679679

680680
def namespaces(self):

rdflib_sqlalchemy/termutils.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
REVERSE_TERM_COMBINATIONS,
1111
)
1212

13-
1413
__all__ = ["extract_triple"]
1514

1615

@@ -148,16 +147,10 @@ def triple_pattern_to_term_combinations(triple):
148147

149148
def type_to_term_combination(member, klass, context):
150149
"""Map a type to a term combination."""
151-
try:
152-
rt = TERM_COMBINATIONS["%sU%s%s" %
153-
(term_to_letter(member),
154-
term_to_letter(klass),
155-
normalize_graph(context)[-1])]
156-
return rt
157-
except:
158-
raise Exception("Unable to persist" +
159-
"classification triple: %s %s %s %s" %
160-
(member, "rdf:type", klass, context))
150+
return TERM_COMBINATIONS["%sU%s%s" %
151+
(term_to_letter(member),
152+
term_to_letter(klass),
153+
normalize_graph(context)[-1])]
161154

162155

163156
def statement_to_term_combination(subject, predicate, obj, context):

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ verbosity = 2
88
[flake8]
99
max-line-length = 120
1010
max-complexity = 15
11+
ignore = E722

test/context_case.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ def setUp(self, uri="sqlite://", storename=None):
3030

3131
def tearDown(self, uri="sqlite://"):
3232
self.graph.destroy(uri)
33-
try:
34-
self.graph.close()
35-
except:
36-
pass
33+
self.graph.close()
3734

3835
def get_context(self, identifier):
3936
assert isinstance(identifier, URIRef) or \

test/graph_case.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ def setUp(self, uri="sqlite://", storename=None):
2929

3030
def tearDown(self, uri="sqlite://"):
3131
self.graph.destroy(uri)
32-
try:
33-
self.graph.close()
34-
except:
35-
pass
32+
self.graph.close()
3633

3734
def addStuff(self):
3835
tarek = self.tarek
@@ -300,7 +297,6 @@ def testStoreLiteralsXmlQuote(self):
300297
o = objs[0]
301298
self.assertEquals(o, (bob, says, imtheone))
302299

303-
304300
xmltestdoc = """<?xml version="1.0" encoding="UTF-8"?>
305301
<rdf:RDF
306302
xmlns="http://example.org/"

test/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
def investigate_len_issue():
2525
store = plugin.get("SQLAlchemy", Store)(
2626
identifier=URIRef("rdflib_test"),
27-
configuration=Literal("sqlite:///%(here)s/development.sqlite" % {
28-
"here": os.getcwd()}))
27+
configuration=Literal(
28+
"sqlite:///%(here)s/development.sqlite" % {"here": os.getcwd()}))
2929
g0 = Graph("Sleepycat")
3030
g0.open("/tmp/foo", create=True)
3131
g1 = Graph(store)

test/test_sqlalchemy.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ def setUp(self):
4040

4141
def tearDown(self):
4242
self.graph.destroy(self.dburi)
43-
try:
44-
self.graph.close()
45-
except:
46-
pass
43+
self.graph.close()
4744

4845
def test_registerplugins(self):
4946
# I doubt this is quite right for a fresh pip installation,

tox.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ deps =
1313

1414
[testenv:lint]
1515
commands = flake8 rdflib_sqlalchemy test
16-
deps=
16+
deps =
1717
flake8
1818
flake8-print
1919

@@ -30,3 +30,8 @@ deps =
3030
[tox:travis]
3131
2.7 = py27, cover, lint
3232
3.5 = py35, lint
33+
34+
[flake8]
35+
max-line-length = 120
36+
max-complexity = 15
37+
ignore = W504,W503

0 commit comments

Comments
 (0)