Skip to content

Commit

Permalink
Add guard inside _trim_arity to protect against black reformatting in…
Browse files Browse the repository at this point in the history
… spacing-critical code
  • Loading branch information
ptmcg committed Mar 21, 2022
1 parent 1c0d77e commit 7661493
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyparsing/__init__.py
Expand Up @@ -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 <ptmcg.gm+pyparsing@gmail.com>"
Expand Down
15 changes: 6 additions & 9 deletions pyparsing/core.py
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 7661493

Please sign in to comment.