From ec48b14d703283baf726ab76529594bd52b2708e Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sat, 13 Mar 2021 18:31:10 -0500 Subject: [PATCH] Squashed 'wrap/' changes from d19cda546..91f3835a8 91f3835a8 Merge pull request #39 from borglab/fix/deepcopy b64e01744 don't remove underscore for instantiations 80c060b52 monkey patch deepcopy issue in pyparsing git-subtree-dir: wrap git-subtree-split: 91f3835a8a69919ccb67435c567803f162faeac7 --- gtwrap/interface_parser.py | 20 ++++++++++++++++++++ gtwrap/template_instantiator.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gtwrap/interface_parser.py b/gtwrap/interface_parser.py index c936cfe11..b4328327f 100644 --- a/gtwrap/interface_parser.py +++ b/gtwrap/interface_parser.py @@ -11,13 +11,33 @@ Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellae # pylint: disable=unnecessary-lambda, unused-import, expression-not-assigned, no-else-return, protected-access, too-few-public-methods, too-many-arguments +import sys import typing +import pyparsing from pyparsing import (CharsNotIn, Forward, Group, Keyword, Literal, OneOrMore, Optional, Or, ParseException, ParserElement, Suppress, Word, ZeroOrMore, alphanums, alphas, cppStyleComment, delimitedList, empty, nums, stringEnd) +# Fix deepcopy issue with pyparsing +# Can remove once https://github.com/pyparsing/pyparsing/issues/208 is resolved. +if sys.version_info >= (3, 8): + def fixed_get_attr(self, item): + """ + Fix for monkey-patching issue with deepcopy in pyparsing.ParseResults + """ + if item == '__deepcopy__': + raise AttributeError(item) + try: + return self[item] + except KeyError: + return "" + + # apply the monkey-patch + pyparsing.ParseResults.__getattr__ = fixed_get_attr + + ParserElement.enablePackrat() # rule for identifiers (e.g. variable names) diff --git a/gtwrap/template_instantiator.py b/gtwrap/template_instantiator.py index 331b20d02..a55a868a3 100644 --- a/gtwrap/template_instantiator.py +++ b/gtwrap/template_instantiator.py @@ -126,7 +126,7 @@ def instantiate_name(original_name, instantiations): inst_name = '' return "{}{}".format(original_name, "".join( - [inst.instantiated_name().capitalize().replace('_', '') for inst in instantiations])) + [inst.instantiated_name().capitalize() for inst in instantiations])) class InstantiatedMethod(parser.Method):