From 508750e836c67f95856824b97d3893c6009dda8f Mon Sep 17 00:00:00 2001 From: Paul McGuire Date: Wed, 19 Aug 2020 22:42:25 -0500 Subject: Convert SyntaxWarnings to ValueError and TypeError exceptions; change diagnostics to an enum, and add enable_diag(), disable_diag() and enable_all_warnings() methods; clean up pyparsing imports in test_unit.py --- pyparsing/helpers.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'pyparsing/helpers.py') diff --git a/pyparsing/helpers.py b/pyparsing/helpers.py index 57219b6..d013975 100644 --- a/pyparsing/helpers.py +++ b/pyparsing/helpers.py @@ -181,8 +181,8 @@ def oneOf(strs, caseless=False, useRegex=True, asKeyword=False): """ if isinstance(caseless, str_type): warnings.warn( - "More than one string argument passed to oneOf, pass " - "choices as a list or space-delimited string", + "More than one string argument passed to oneOf, pass" + " choices as a list or space-delimited string", stacklevel=2, ) @@ -201,11 +201,7 @@ def oneOf(strs, caseless=False, useRegex=True, asKeyword=False): elif isinstance(strs, Iterable): symbols = list(strs) else: - warnings.warn( - "Invalid argument to oneOf, expected string or iterable", - SyntaxWarning, - stacklevel=2, - ) + raise TypeError("Invalid argument to oneOf, expected string or iterable") if not symbols: return NoMatch() @@ -239,9 +235,7 @@ def oneOf(strs, caseless=False, useRegex=True, asKeyword=False): ) except sre_constants.error: warnings.warn( - "Exception creating Regex for oneOf, building MatchFirst", - SyntaxWarning, - stacklevel=2, + "Exception creating Regex for oneOf, building MatchFirst", stacklevel=2 ) # last resort, just use MatchFirst @@ -600,9 +594,9 @@ def replaceHTMLEntity(t): return _htmlEntityMap.get(t.entity) -opAssoc = types.SimpleNamespace() -opAssoc.LEFT = object() -opAssoc.RIGHT = object() +class opAssoc(Enum): + LEFT = auto() + RIGHT = auto() def infixNotation(baseExpr, opList, lpar=Suppress("("), rpar=Suppress(")")): -- cgit v1.2.1