From 9a16a420312c615210ca213daab349302532fe1e Mon Sep 17 00:00:00 2001 From: Michael Weiss Date: Wed, 14 Jan 2026 20:52:50 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20type=20checking=20for=20encod?= =?UTF-8?q?er/decoder=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bibtexparser/middlewares/latex_encoding.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bibtexparser/middlewares/latex_encoding.py b/bibtexparser/middlewares/latex_encoding.py index 9556c91..c11ed8e 100644 --- a/bibtexparser/middlewares/latex_encoding.py +++ b/bibtexparser/middlewares/latex_encoding.py @@ -102,10 +102,15 @@ def __init__( if encoder is not None and (keep_math is not None or enclose_urls is not None): raise ValueError( - "Cannot specify both encoder and keep_math or enclose_urls." + "Cannot specify both encoder and keep_math or enclose_urls. " "If you want to use a custom encoder, you have to specify it completely." ) + if encoder is not None and not isinstance(encoder, UnicodeToLatexEncoder): + raise TypeError( + f"encoder must be a UnicodeToLatexEncoder instance, got {type(encoder).__name__}" + ) + # Defaults (not specified as defaults in args, # to make sure we can identify if they were specified) keep_math = keep_math if keep_math is not None else True @@ -167,11 +172,16 @@ def __init__( if decoder is not None and (keep_braced_groups is not None or keep_math_mode is not None): raise ValueError( "Cannot specify both decoder and one of " - "`keep_braced_groups` or `keep_math_mode`." + "`keep_braced_groups` or `keep_math_mode`. " "If you want to use a custom decoder, " "you have to specify it completely." ) + if decoder is not None and not isinstance(decoder, LatexNodes2Text): + raise TypeError( + f"decoder must be a LatexNodes2Text instance, got {type(decoder).__name__}" + ) + # Defaults (not specified as defaults in args, # to make sure we can identify if they were specified) keep_braced_groups = keep_braced_groups if keep_braced_groups is not None else False