Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.

Commit 16d7a05

Browse files
author
Reece Hart
committed
Close #192: use variable for long string literals in exceptions
1 parent 32f1206 commit 16d7a05

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ select = [
201201
"A001", # Variable `id` is shadowing a Python builtin
202202
"A002", # Function argument `id` is shadowing a Python builtin
203203
"B006", # Do not use mutable data structures for argument defaults
204-
"EM101", # Exception must not use a string literal, assign to variable first
205-
"EM102", # Exception must not use an f-string literal, assign to variable first
206204
"F522", # `.format` call has unused named argument(s): n
207205
"F524", # `.format` call is missing argument(s) for placeholder(s): n=n
208206
"F821", # Undefined name `pas`

src/biocommons/eutils/_internal/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def efetch(self, db, id):
8686
return ExchangeSet(xml)
8787
if db in ["pmc"]:
8888
return PubmedCentralArticleSet(doc)
89-
raise EutilsError(f"database {db} is not currently supported by eutils")
89+
msg = f"database {db} is not currently supported by eutils"
90+
raise EutilsError(msg)
9091

9192

9293
# <LICENSE>

src/biocommons/eutils/_internal/xmlfacades/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def __init__(self, xml):
3131
raise EutilsError("Cannot create object from type " + type(xml).__name__)
3232

3333
if self._root_tag is None:
34-
raise EutilsError(f"_root_tag not defined for class {type(self).__name__}")
34+
msg = f"_root_tag not defined for class {type(self).__name__}"
35+
raise EutilsError(msg)
3536
if self._root_tag != self._xml_root.tag:
36-
raise EutilsError(
37-
f"XML for {type(self).__name__} object must be a {self._root_tag} element (got {self._xml_root.tag})"
38-
)
37+
msg = f"XML for {type(self).__name__} object must be a {self._root_tag} element (got {self._xml_root.tag})"
38+
raise EutilsError(msg)
3939

4040

4141
# <LICENSE>

src/biocommons/eutils/_internal/xmlfacades/einforesult.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def type(self):
3030
return "dbinfo"
3131
if childtag == "DbList":
3232
return "dblist"
33-
raise RuntimeError("Shouldn't be here; EInfoResult contains neither a DbList nor a DbInfo")
33+
msg = "Shouldn't be here; EInfoResult contains neither a DbList nor a DbInfo"
34+
raise RuntimeError(msg)
3435

3536
@property
3637
def dbinfo(self):

src/biocommons/eutils/_internal/xmlfacades/gbseq.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def gene(self):
4949

5050
@property
5151
def genes(self):
52-
raise RuntimeError("The genes property is obsolete; use gene instead")
52+
msg = "The genes property is obsolete; use gene instead"
53+
raise RuntimeError(msg)
5354

5455
@property
5556
def gi(self):

src/biocommons/eutils/_internal/xmlfacades/genecommentary.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ def acv(self):
3434
def genomic_coords(self):
3535
n = self._xml_root.find("Gene-commentary_genomic-coords")
3636
if n is None:
37-
raise EutilsError(
38-
f"this object (type={self.type}) does not have genomic coordinates defined (mRNA and peptide typically do)"
39-
)
37+
msg = f"this object (type={self.type}) does not have genomic coordinates defined (mRNA and peptide typically do)"
38+
raise EutilsError(msg)
4039
return GeneCommentaryGenomicCoords(n)
4140

4241
@property

0 commit comments

Comments
 (0)