Skip to content

Commit 5d7f8f1

Browse files
authored
♻️ Replace assertions with explicit exceptions (#505)
1 parent fc6748d commit 5d7f8f1

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

bibtexparser/library.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,22 @@ def replace(self, old_block: Block, new_block: Block, fail_on_duplicate_key: boo
107107
def _cast_to_duplicate(
108108
prev_block_with_same_key: Union[Entry, String], duplicate: Union[Entry, String]
109109
):
110-
assert isinstance(prev_block_with_same_key, type(duplicate)) or isinstance(
111-
duplicate, type(prev_block_with_same_key)
112-
), (
113-
"Internal BibtexParser Error. Duplicate blocks share no common type."
114-
f"Found {type(prev_block_with_same_key)} and {type(duplicate)}, but both should be"
115-
f"either instance of String or instance of Entry."
116-
f"Please report this issue at the bibtexparser issue tracker.",
117-
)
118-
119-
assert (
120-
prev_block_with_same_key.key == duplicate.key
121-
), "Internal BibtexParser Error. Duplicate blocks have different keys."
110+
if not (
111+
isinstance(prev_block_with_same_key, type(duplicate))
112+
or isinstance(duplicate, type(prev_block_with_same_key))
113+
):
114+
raise ValueError(
115+
"Internal BibtexParser Error. Duplicate blocks share no common type. "
116+
f"Found {type(prev_block_with_same_key)} and {type(duplicate)}, but both should be "
117+
"either instance of String or instance of Entry. "
118+
"Please report this issue at the bibtexparser issue tracker."
119+
)
120+
121+
if prev_block_with_same_key.key != duplicate.key:
122+
raise ValueError(
123+
"Internal BibtexParser Error. Duplicate blocks have different keys. "
124+
"Please report this issue at the bibtexparser issue tracker."
125+
)
122126

123127
return DuplicateBlockKeyBlock(
124128
start_line=duplicate.start_line,

0 commit comments

Comments
 (0)