From 4d3ccfaa7e6792d7673a86de5763481afdd825d2 Mon Sep 17 00:00:00 2001 From: Darkdadaah Date: Wed, 1 Apr 2026 18:41:49 +0200 Subject: [PATCH] Add option to not print output Add 'quiet_output' to Wtp to not print errors to stdout via _fmt_errmsg() --- src/wikitextprocessor/core.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wikitextprocessor/core.py b/src/wikitextprocessor/core.py index 413dcb36..d96f7c08 100644 --- a/src/wikitextprocessor/core.py +++ b/src/wikitextprocessor/core.py @@ -283,6 +283,7 @@ class Wtp: "wiki_notices", # WIKI error messages "wikidata_session", "linktrailing_re", + "quiet_output", # Prevent errors printed to stdout ) def __init__( @@ -294,6 +295,7 @@ def __init__( extension_tags: Optional[dict[str, HTMLTagData]] = None, parser_function_aliases: dict[str, str] = {}, quiet: bool = False, + quiet_output: bool = False, ): if isinstance(db_path, str): self.db_path: Optional[Path] = Path(db_path) @@ -355,6 +357,7 @@ def __init__( self.parser_function_aliases = parser_function_aliases if not quiet: logger.setLevel(logging.DEBUG) + self.quiet_output = quiet_output self.wikidata_session: Session | None = None # Default regex pattern, will sometimes cause trouble. # Linktrailing is when you have [[a li]]nk that consumes the @@ -494,6 +497,8 @@ def init_namespace_data(self) -> None: } def _fmt_errmsg(self, kind: str, msg: str, trace: Optional[str]) -> None: + if self.quiet_output: + return assert isinstance(kind, str) assert isinstance(msg, str) assert isinstance(trace, (str, type(None)))