summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIwan Aucamp <aucampia@gmail.com>2023-04-12 22:11:02 +0200
committerGitHub <noreply@github.com>2023-04-12 22:11:02 +0200
commit4ea14367ffa2c05e5c288842982dcc3cdd194dd6 (patch)
tree4e82b7461510de574c5912af1a6e15d05ffc14ec
parent7df77cd3fa0381ae2b309981230eaa0d42e90b79 (diff)
downloadrdflib-4ea14367ffa2c05e5c288842982dcc3cdd194dd6.tar.gz
fix: eliminate bare `except:` (#2350)
Replace bare `except:` with `except Exception`, there are some cases where it can be narrowed further, but this is already an improvement over the current situation. This is somewhat pursuant to eliminating [flakeheaven](https://github.com/flakeheaven/flakeheaven), as it no longer supports the latest version of flake8 [[ref](https://github.com/flakeheaven/flakeheaven/issues/132)]. But it also is just the right thing to do as bare exceptions can cause problems.
-rw-r--r--rdflib/namespace/__init__.py2
-rwxr-xr-xrdflib/plugins/parsers/notation3.py4
-rw-r--r--rdflib/plugins/parsers/trix.py4
-rw-r--r--rdflib/plugins/serializers/longturtle.py4
-rw-r--r--rdflib/plugins/serializers/rdfxml.py2
-rw-r--r--rdflib/plugins/serializers/turtle.py4
-rw-r--r--rdflib/query.py2
-rw-r--r--rdflib/tools/csv2rdf.py2
-rw-r--r--rdflib/tools/rdf2dot.py4
-rw-r--r--rdflib/tools/rdfs2dot.py2
10 files changed, 15 insertions, 15 deletions
diff --git a/rdflib/namespace/__init__.py b/rdflib/namespace/__init__.py
index d96c21f3..8455e2b6 100644
--- a/rdflib/namespace/__init__.py
+++ b/rdflib/namespace/__init__.py
@@ -508,7 +508,7 @@ class NamespaceManager:
if namespace not in self.__strie:
insert_strie(self.__strie, self.__trie, str(namespace))
namespace = URIRef(str(namespace))
- except:
+ except Exception:
if isinstance(rdfTerm, Variable):
return "?%s" % rdfTerm
else:
diff --git a/rdflib/plugins/parsers/notation3.py b/rdflib/plugins/parsers/notation3.py
index 08798076..2a64be24 100755
--- a/rdflib/plugins/parsers/notation3.py
+++ b/rdflib/plugins/parsers/notation3.py
@@ -353,7 +353,7 @@ numberCharsPlus = numberChars | {"+", "."}
def unicodeExpand(m: Match) -> str:
try:
return chr(int(m.group(1), 16))
- except:
+ except Exception:
raise Exception("Invalid unicode code point: " + m.group(1))
@@ -1711,7 +1711,7 @@ class SinkParser:
)
try:
return i + n, reg.sub(unicodeExpand, "\\" + prefix + argstr[i : i + n])
- except:
+ except Exception:
raise BadSyntax(
self._thisDoc,
startline,
diff --git a/rdflib/plugins/parsers/trix.py b/rdflib/plugins/parsers/trix.py
index 187c6d45..8baaf5ca 100644
--- a/rdflib/plugins/parsers/trix.py
+++ b/rdflib/plugins/parsers/trix.py
@@ -105,7 +105,7 @@ class TriXHandler(handler.ContentHandler):
try:
self.lang = attrs.getValue((str(XMLNS), "lang"))
- except:
+ except Exception:
# language not required - ignore
pass
try:
@@ -122,7 +122,7 @@ class TriXHandler(handler.ContentHandler):
self.datatype = None
try:
self.lang = attrs.getValue((str(XMLNS), "lang"))
- except:
+ except Exception:
# language not required - ignore
pass
diff --git a/rdflib/plugins/serializers/longturtle.py b/rdflib/plugins/serializers/longturtle.py
index 263604fa..ac2febdc 100644
--- a/rdflib/plugins/serializers/longturtle.py
+++ b/rdflib/plugins/serializers/longturtle.py
@@ -124,7 +124,7 @@ class LongTurtleSerializer(RecursiveSerializer):
try:
parts = self.store.compute_qname(uri, generate=gen_prefix)
- except:
+ except Exception:
# is the uri a namespace in itself?
pfx = self.store.store.prefix(uri)
@@ -245,7 +245,7 @@ class LongTurtleSerializer(RecursiveSerializer):
try:
if self.store.value(l_, RDF.first) is None:
return False
- except:
+ except Exception:
return False
while l_:
if l_ != RDF.nil and len(list(self.store.predicate_objects(l_))) != 2:
diff --git a/rdflib/plugins/serializers/rdfxml.py b/rdflib/plugins/serializers/rdfxml.py
index e3d9ec77..c5acc74a 100644
--- a/rdflib/plugins/serializers/rdfxml.py
+++ b/rdflib/plugins/serializers/rdfxml.py
@@ -253,7 +253,7 @@ class PrettyXMLSerializer(Serializer):
try:
# type error: Argument 1 to "qname" of "NamespaceManager" has incompatible type "Optional[Node]"; expected "str"
self.nm.qname(type) # type: ignore[arg-type]
- except:
+ except Exception:
type = None
element = type or RDFVOC.Description
diff --git a/rdflib/plugins/serializers/turtle.py b/rdflib/plugins/serializers/turtle.py
index ff4cd164..ad118247 100644
--- a/rdflib/plugins/serializers/turtle.py
+++ b/rdflib/plugins/serializers/turtle.py
@@ -273,7 +273,7 @@ class TurtleSerializer(RecursiveSerializer):
try:
parts = self.store.compute_qname(uri, generate=gen_prefix)
- except:
+ except Exception:
# is the uri a namespace in itself?
pfx = self.store.store.prefix(uri)
@@ -397,7 +397,7 @@ class TurtleSerializer(RecursiveSerializer):
try:
if self.store.value(l_, RDF.first) is None:
return False
- except:
+ except Exception:
return False
while l_:
if l_ != RDF.nil and len(list(self.store.predicate_objects(l_))) != 2:
diff --git a/rdflib/query.py b/rdflib/query.py
index e9c18901..261ffde9 100644
--- a/rdflib/query.py
+++ b/rdflib/query.py
@@ -409,7 +409,7 @@ class Result:
return self.vars == other.vars and self.bindings == other.bindings
else:
return self.graph == other.graph
- except:
+ except Exception:
return False
diff --git a/rdflib/tools/csv2rdf.py b/rdflib/tools/csv2rdf.py
index 267483ed..fe740356 100644
--- a/rdflib/tools/csv2rdf.py
+++ b/rdflib/tools/csv2rdf.py
@@ -414,7 +414,7 @@ class CSV2RDF:
"%d rows, %d triples, elapsed %.2fs.\n"
% (rows, self.triples, time.time() - start)
)
- except:
+ except Exception:
sys.stderr.write("Error processing line: %d\n" % rows)
raise
diff --git a/rdflib/tools/rdf2dot.py b/rdflib/tools/rdf2dot.py
index 1a33ee26..0ca1fa1e 100644
--- a/rdflib/tools/rdf2dot.py
+++ b/rdflib/tools/rdf2dot.py
@@ -98,7 +98,7 @@ def rdf2dot(g, stream, opts={}):
return l_
try:
return g.namespace_manager.compute_qname(x)[2]
- except:
+ except Exception:
return x
def formatliteral(l, g):
@@ -113,7 +113,7 @@ def rdf2dot(g, stream, opts={}):
try:
q = g.compute_qname(x)
return q[0] + ":" + q[2]
- except:
+ except Exception:
return x
def color(p):
diff --git a/rdflib/tools/rdfs2dot.py b/rdflib/tools/rdfs2dot.py
index 69ecfba5..4e639b48 100644
--- a/rdflib/tools/rdfs2dot.py
+++ b/rdflib/tools/rdfs2dot.py
@@ -87,7 +87,7 @@ def rdfs2dot(g, stream, opts={}):
if lbl is None:
try:
lbl = grf.namespace_manager.compute_qname(xx)[2]
- except:
+ except Exception:
pass # bnodes and some weird URIs cannot be split
return lbl