diff options
author | Paul McGuire <ptmcg@users.noreply.github.com> | 2020-08-19 22:42:25 -0500 |
---|---|---|
committer | Paul McGuire <ptmcg@users.noreply.github.com> | 2020-08-19 22:42:25 -0500 |
commit | 508750e836c67f95856824b97d3893c6009dda8f (patch) | |
tree | da4b7981283c22d5e1da11e011bf5f9ef9dcf165 /pyparsing/helpers.py | |
parent | af90c6d42bfb1288c30d0e44046b0e2819ad54d6 (diff) | |
download | pyparsing-git-508750e836c67f95856824b97d3893c6009dda8f.tar.gz |
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
Diffstat (limited to 'pyparsing/helpers.py')
-rw-r--r-- | pyparsing/helpers.py | 20 |
1 files changed, 7 insertions, 13 deletions
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(")")): |