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
release/4.3a0
Varun Agrawal 2021-03-13 18:31:10 -05:00
parent 55dade0b8e
commit ec48b14d70
2 changed files with 21 additions and 1 deletions

View File

@ -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 # 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 typing
import pyparsing
from pyparsing import (CharsNotIn, Forward, Group, Keyword, Literal, OneOrMore, from pyparsing import (CharsNotIn, Forward, Group, Keyword, Literal, OneOrMore,
Optional, Or, ParseException, ParserElement, Suppress, Optional, Or, ParseException, ParserElement, Suppress,
Word, ZeroOrMore, alphanums, alphas, cppStyleComment, Word, ZeroOrMore, alphanums, alphas, cppStyleComment,
delimitedList, empty, nums, stringEnd) 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() ParserElement.enablePackrat()
# rule for identifiers (e.g. variable names) # rule for identifiers (e.g. variable names)

View File

@ -126,7 +126,7 @@ def instantiate_name(original_name, instantiations):
inst_name = '' inst_name = ''
return "{}{}".format(original_name, "".join( 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): class InstantiatedMethod(parser.Method):