diff options
author | ptmcg <ptmcg@austin.rr.com> | 2021-10-22 17:43:16 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2021-10-22 17:43:16 -0500 |
commit | 686852fa90700d8434082cf151af36ea000c2418 (patch) | |
tree | b77cedfbdd56782c1b854cd852150cdf8f80d383 /pyparsing/core.py | |
parent | 3edde380a24a4bcef346519298f52a3d324c2d17 (diff) | |
download | pyparsing-git-686852fa90700d8434082cf151af36ea000c2418.tar.gz |
Added support for python -W warning option to call enable_all_warnings() at startup. Also detects setting of PYPARSINGENABLEALLWARNINGS environment variable to any non-blank value.
Diffstat (limited to 'pyparsing/core.py')
-rw-r--r-- | pyparsing/core.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/pyparsing/core.py b/pyparsing/core.py index d77599e..3b7d62f 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -1,6 +1,7 @@ # # core.py # +import os from typing import ( Optional as OptionalType, Iterable as IterableType, @@ -20,6 +21,7 @@ import copy import warnings import re import sre_constants +import sys from collections.abc import Iterable import traceback import types @@ -173,6 +175,26 @@ def enable_all_warnings(): # hide abstract class del __config_flags + +def _should_enable_warnings(cmd_line_warn_options: List[str], warn_env_var: str) -> bool: + enable = bool(warn_env_var) + for warn_opt in cmd_line_warn_options: + w_action, w_message, w_category, w_module, w_line = (warn_opt + "::::").split( + ":" + )[:5] + if not w_action.lower().startswith("i") and ( + not (w_message or w_category or w_module) or w_module == "pyparsing" + ): + enable = True + elif w_action.lower().startswith("i") and w_module in ("pyparsing", ""): + enable = False + return enable + + +if _should_enable_warnings(sys.warnoptions, os.environ.get("PYPARSINGENABLEALLWARNINGS")): + enable_all_warnings() + + # build list of single arg builtins, that can be used as parse actions _single_arg_builtins = { sum, |