Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: eliminate bare except: #2350

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rdflib/namespace/__init__.py
Original file line number Diff line number Diff line change
@@ -480,7 +480,7 @@ def normalizeUri(self, rdfTerm: str) -> str:
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:
4 changes: 2 additions & 2 deletions rdflib/plugins/parsers/notation3.py
Original file line number Diff line number Diff line change
@@ -353,7 +353,7 @@ def becauseSubexpression(*args: Any, **kargs: Any) -> None:
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 @@ def _unicodeEscape(
)
try:
return i + n, reg.sub(unicodeExpand, "\\" + prefix + argstr[i : i + n])
except:
except Exception:
raise BadSyntax(
self._thisDoc,
startline,
4 changes: 2 additions & 2 deletions rdflib/plugins/parsers/trix.py
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ def startElementNS(

try:
self.lang = attrs.getValue((str(XMLNS), "lang"))
except:
except Exception:
# language not required - ignore
pass
try:
@@ -122,7 +122,7 @@ def startElementNS(
self.datatype = None
try:
self.lang = attrs.getValue((str(XMLNS), "lang"))
except:
except Exception:
# language not required - ignore
pass

4 changes: 2 additions & 2 deletions rdflib/plugins/serializers/longturtle.py
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ def getQName(self, uri, gen_prefix=True):

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 @@ def isValidList(self, l_):
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:
2 changes: 1 addition & 1 deletion rdflib/plugins/serializers/rdfxml.py
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ def subject(self, subject: IdentifiedNode, depth: int = 1):
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
4 changes: 2 additions & 2 deletions rdflib/plugins/serializers/turtle.py
Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ def getQName(self, uri, gen_prefix=True):

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 @@ def isValidList(self, l_):
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:
2 changes: 1 addition & 1 deletion rdflib/query.py
Original file line number Diff line number Diff line change
@@ -409,7 +409,7 @@ def __eq__(self, other: Any) -> bool:
return self.vars == other.vars and self.bindings == other.bindings
else:
return self.graph == other.graph
except:
except Exception:
return False


2 changes: 1 addition & 1 deletion rdflib/tools/csv2rdf.py
Original file line number Diff line number Diff line change
@@ -414,7 +414,7 @@ def convert(self, csvreader):
"%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

4 changes: 2 additions & 2 deletions rdflib/tools/rdf2dot.py
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ def label(x, g):
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 qname(x, g):
try:
q = g.compute_qname(x)
return q[0] + ":" + q[2]
except:
except Exception:
return x

def color(p):
2 changes: 1 addition & 1 deletion rdflib/tools/rdfs2dot.py
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ def label(xx, grf):
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