fix: eliminate bare except: (#2350) · RDFLib/rdflib@4ea1436 (original) (raw)

10 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -508,7 +508,7 @@ def normalizeUri(self, rdfTerm: str) -> str:
508 508 if namespace not in self.__strie:
509 509 insert_strie(self.__strie, self.__trie, str(namespace))
510 510 namespace = URIRef(str(namespace))
511 -except:
511 +except Exception:
512 512 if isinstance(rdfTerm, Variable):
513 513 return "?%s" % rdfTerm
514 514 else:
Original file line number Diff line number Diff line change
@@ -353,7 +353,7 @@ def becauseSubexpression(*args: Any, **kargs: Any) -> None:
353 353 def unicodeExpand(m: Match) -> str:
354 354 try:
355 355 return chr(int(m.group(1), 16))
356 -except:
356 +except Exception:
357 357 raise Exception("Invalid unicode code point: " + m.group(1))
358 358
359 359
@@ -1711,7 +1711,7 @@ def _unicodeEscape(
1711 1711 )
1712 1712 try:
1713 1713 return i + n, reg.sub(unicodeExpand, "\\" + prefix + argstr[i : i + n])
1714 -except:
1714 +except Exception:
1715 1715 raise BadSyntax(
1716 1716 self._thisDoc,
1717 1717 startline,
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ def startElementNS(
105 105
106 106 try:
107 107 self.lang = attrs.getValue((str(XMLNS), "lang"))
108 -except:
108 +except Exception:
109 109 # language not required - ignore
110 110 pass
111 111 try:
@@ -122,7 +122,7 @@ def startElementNS(
122 122 self.datatype = None
123 123 try:
124 124 self.lang = attrs.getValue((str(XMLNS), "lang"))
125 -except:
125 +except Exception:
126 126 # language not required - ignore
127 127 pass
128 128
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ def getQName(self, uri, gen_prefix=True):
124 124
125 125 try:
126 126 parts = self.store.compute_qname(uri, generate=gen_prefix)
127 -except:
127 +except Exception:
128 128 # is the uri a namespace in itself?
129 129 pfx = self.store.store.prefix(uri)
130 130
@@ -245,7 +245,7 @@ def isValidList(self, l_):
245 245 try:
246 246 if self.store.value(l_, RDF.first) is None:
247 247 return False
248 -except:
248 +except Exception:
249 249 return False
250 250 while l_:
251 251 if l_ != RDF.nil and len(list(self.store.predicate_objects(l_))) != 2:
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ def subject(self, subject: IdentifiedNode, depth: int = 1):
253 253 try:
254 254 # type error: Argument 1 to "qname" of "NamespaceManager" has incompatible type "Optional[Node]"; expected "str"
255 255 self.nm.qname(type) # type: ignore[arg-type]
256 -except:
256 +except Exception:
257 257 type = None
258 258
259 259 element = type or RDFVOC.Description
Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ def getQName(self, uri, gen_prefix=True):
273 273
274 274 try:
275 275 parts = self.store.compute_qname(uri, generate=gen_prefix)
276 -except:
276 +except Exception:
277 277 # is the uri a namespace in itself?
278 278 pfx = self.store.store.prefix(uri)
279 279
@@ -397,7 +397,7 @@ def isValidList(self, l_):
397 397 try:
398 398 if self.store.value(l_, RDF.first) is None:
399 399 return False
400 -except:
400 +except Exception:
401 401 return False
402 402 while l_:
403 403 if l_ != RDF.nil and len(list(self.store.predicate_objects(l_))) != 2:
Original file line number Diff line number Diff line change
@@ -409,7 +409,7 @@ def __eq__(self, other: Any) -> bool:
409 409 return self.vars == other.vars and self.bindings == other.bindings
410 410 else:
411 411 return self.graph == other.graph
412 -except:
412 +except Exception:
413 413 return False
414 414
415 415
Original file line number Diff line number Diff line change
@@ -414,7 +414,7 @@ def convert(self, csvreader):
414 414 "%d rows, %d triples, elapsed %.2fs.\n"
415 415 % (rows, self.triples, time.time() - start)
416 416 )
417 -except:
417 +except Exception:
418 418 sys.stderr.write("Error processing line: %d\n" % rows)
419 419 raise
420 420
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ def label(x, g):
98 98 return l_
99 99 try:
100 100 return g.namespace_manager.compute_qname(x)[2]
101 -except:
101 +except Exception:
102 102 return x
103 103
104 104 def formatliteral(l, g):
@@ -113,7 +113,7 @@ def qname(x, g):
113 113 try:
114 114 q = g.compute_qname(x)
115 115 return q[0] + ":" + q[2]
116 -except:
116 +except Exception:
117 117 return x
118 118
119 119 def color(p):
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ def label(xx, grf):
87 87 if lbl is None:
88 88 try:
89 89 lbl = grf.namespace_manager.compute_qname(xx)[2]
90 -except:
90 +except Exception:
91 91 pass # bnodes and some weird URIs cannot be split
92 92 return lbl
93 93