Skip to content

Commit 4ea1436

Browse files
authored
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](flakeheaven/flakeheaven#132)]. But it also is just the right thing to do as bare exceptions can cause problems.
1 parent 7df77cd commit 4ea1436

File tree

10 files changed

+15
-15
lines changed

10 files changed

+15
-15
lines changed

rdflib/namespace/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def normalizeUri(self, rdfTerm: str) -> str:
508508
if namespace not in self.__strie:
509509
insert_strie(self.__strie, self.__trie, str(namespace))
510510
namespace = URIRef(str(namespace))
511-
except:
511+
except Exception:
512512
if isinstance(rdfTerm, Variable):
513513
return "?%s" % rdfTerm
514514
else:

rdflib/plugins/parsers/notation3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def becauseSubexpression(*args: Any, **kargs: Any) -> None:
353353
def unicodeExpand(m: Match) -> str:
354354
try:
355355
return chr(int(m.group(1), 16))
356-
except:
356+
except Exception:
357357
raise Exception("Invalid unicode code point: " + m.group(1))
358358

359359

@@ -1711,7 +1711,7 @@ def _unicodeEscape(
17111711
)
17121712
try:
17131713
return i + n, reg.sub(unicodeExpand, "\\" + prefix + argstr[i : i + n])
1714-
except:
1714+
except Exception:
17151715
raise BadSyntax(
17161716
self._thisDoc,
17171717
startline,

rdflib/plugins/parsers/trix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def startElementNS(
105105

106106
try:
107107
self.lang = attrs.getValue((str(XMLNS), "lang"))
108-
except:
108+
except Exception:
109109
# language not required - ignore
110110
pass
111111
try:
@@ -122,7 +122,7 @@ def startElementNS(
122122
self.datatype = None
123123
try:
124124
self.lang = attrs.getValue((str(XMLNS), "lang"))
125-
except:
125+
except Exception:
126126
# language not required - ignore
127127
pass
128128

rdflib/plugins/serializers/longturtle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def getQName(self, uri, gen_prefix=True):
124124

125125
try:
126126
parts = self.store.compute_qname(uri, generate=gen_prefix)
127-
except:
127+
except Exception:
128128
# is the uri a namespace in itself?
129129
pfx = self.store.store.prefix(uri)
130130

@@ -245,7 +245,7 @@ def isValidList(self, l_):
245245
try:
246246
if self.store.value(l_, RDF.first) is None:
247247
return False
248-
except:
248+
except Exception:
249249
return False
250250
while l_:
251251
if l_ != RDF.nil and len(list(self.store.predicate_objects(l_))) != 2:

rdflib/plugins/serializers/rdfxml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def subject(self, subject: IdentifiedNode, depth: int = 1):
253253
try:
254254
# type error: Argument 1 to "qname" of "NamespaceManager" has incompatible type "Optional[Node]"; expected "str"
255255
self.nm.qname(type) # type: ignore[arg-type]
256-
except:
256+
except Exception:
257257
type = None
258258

259259
element = type or RDFVOC.Description

rdflib/plugins/serializers/turtle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def getQName(self, uri, gen_prefix=True):
273273

274274
try:
275275
parts = self.store.compute_qname(uri, generate=gen_prefix)
276-
except:
276+
except Exception:
277277
# is the uri a namespace in itself?
278278
pfx = self.store.store.prefix(uri)
279279

@@ -397,7 +397,7 @@ def isValidList(self, l_):
397397
try:
398398
if self.store.value(l_, RDF.first) is None:
399399
return False
400-
except:
400+
except Exception:
401401
return False
402402
while l_:
403403
if l_ != RDF.nil and len(list(self.store.predicate_objects(l_))) != 2:

rdflib/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def __eq__(self, other: Any) -> bool:
409409
return self.vars == other.vars and self.bindings == other.bindings
410410
else:
411411
return self.graph == other.graph
412-
except:
412+
except Exception:
413413
return False
414414

415415

rdflib/tools/csv2rdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def convert(self, csvreader):
414414
"%d rows, %d triples, elapsed %.2fs.\n"
415415
% (rows, self.triples, time.time() - start)
416416
)
417-
except:
417+
except Exception:
418418
sys.stderr.write("Error processing line: %d\n" % rows)
419419
raise
420420

rdflib/tools/rdf2dot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def label(x, g):
9898
return l_
9999
try:
100100
return g.namespace_manager.compute_qname(x)[2]
101-
except:
101+
except Exception:
102102
return x
103103

104104
def formatliteral(l, g):
@@ -113,7 +113,7 @@ def qname(x, g):
113113
try:
114114
q = g.compute_qname(x)
115115
return q[0] + ":" + q[2]
116-
except:
116+
except Exception:
117117
return x
118118

119119
def color(p):

rdflib/tools/rdfs2dot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def label(xx, grf):
8787
if lbl is None:
8888
try:
8989
lbl = grf.namespace_manager.compute_qname(xx)[2]
90-
except:
90+
except Exception:
9191
pass # bnodes and some weird URIs cannot be split
9292
return lbl
9393

0 commit comments

Comments
 (0)