From d0f76d150f2c1eeeb7274dcd771f82e1ffcdeb34 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Tue, 7 Feb 2023 14:34:47 -0800 Subject: [PATCH] Make default quiet for underscores --- masque/library.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/masque/library.py b/masque/library.py index 6179bca..644fff2 100644 --- a/masque/library.py +++ b/masque/library.py @@ -254,7 +254,7 @@ class Library(Mapping[str, 'Pattern'], metaclass=ABCMeta): name: str = '__', sanitize: bool = True, max_length: int = 32, - quiet: bool = False, + quiet: Optional[bool] = None, ) -> str: """ Find a unique name for the pattern. @@ -265,11 +265,15 @@ class Library(Mapping[str, 'Pattern'], metaclass=ABCMeta): name: Preferred name for the pattern. Default '__'. sanitize: Allows only alphanumeric charaters and _?$. Replaces invalid characters with underscores. max_length: Names longer than this will be truncated. - quiet: If `True`, suppress log messages. + quiet: If `True`, suppress log messages. Default `None` suppresses messages only if + the name starts with an underscore. Returns: Name, unique within this library. """ + if quiet is None: + quiet = name.startswith('_') + if sanitize: # Remove invalid characters sanitized_name = re.compile(r'[^A-Za-z0-9_\?\$]').sub('_', name)