From 76614939d4303f4f02c941e0bba64b8054315672 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Mon, 21 Mar 2022 10:42:29 -0500 Subject: [PATCH] Add guard inside _trim_arity to protect against black reformatting in spacing-critical code --- pyparsing/__init__.py | 2 +- pyparsing/core.py | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pyparsing/__init__.py b/pyparsing/__init__.py index 8c6460c6..458e1a0d 100644 --- a/pyparsing/__init__.py +++ b/pyparsing/__init__.py @@ -129,7 +129,7 @@ def __repr__(self): __version_info__ = version_info(3, 0, 8, "final", 0) -__version_time__ = "15 Feb 2022 06:11 UTC" +__version_time__ = "21 Mar 2022 15:41 UTC" __version__ = __version_info__.__version__ __versionTime__ = __version_time__ __author__ = "Paul McGuire " diff --git a/pyparsing/core.py b/pyparsing/core.py index f7d174ae..af66c043 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -259,7 +259,7 @@ def _should_enable_warnings( alphanums = alphas + nums printables = "".join([c for c in string.printable if c not in string.whitespace]) -_trim_arity_call_line = None +_trim_arity_call_line: traceback.StackSummary = None def _trim_arity(func, maxargs=2): @@ -280,16 +280,12 @@ def extract_tb(tb, limit=0): # synthesize what would be returned by traceback.extract_stack at the call to # user's parse action 'func', so that we don't incur call penalty at parse time - LINE_DIFF = 11 + # fmt: off + LINE_DIFF = 7 # IF ANY CODE CHANGES, EVEN JUST COMMENTS OR BLANK LINES, BETWEEN THE NEXT LINE AND # THE CALL TO FUNC INSIDE WRAPPER, LINE_DIFF MUST BE MODIFIED!!!! - _trim_arity_call_line = ( - _trim_arity_call_line or traceback.extract_stack(limit=2)[-1] - ) - pa_call_line_synth = ( - _trim_arity_call_line[0], - _trim_arity_call_line[1] + LINE_DIFF, - ) + _trim_arity_call_line = (_trim_arity_call_line or traceback.extract_stack(limit=2)[-1]) + pa_call_line_synth = (_trim_arity_call_line[0], _trim_arity_call_line[1] + LINE_DIFF) def wrapper(*args): nonlocal found_arity, limit @@ -315,6 +311,7 @@ def wrapper(*args): continue raise + # fmt: on # copy func name to wrapper for sensible debug output # (can't use functools.wraps, since that messes with function signature)