Skip to content
Snippets Groups Projects
Commit ddbc758e authored by Ask Hjorth Larsen's avatar Ask Hjorth Larsen
Browse files

avoid mutable defaults like [], {} in method declarations

parent cb80579d
Branches
Tags
No related merge requests found
......@@ -27,7 +27,7 @@ annotate = False
class PushbackLineFile(object):
"""a file interface where it is possible to put back read lines"""
def __init__(self, fIn, lines = []):
def __init__(self, fIn, lines=tuple()):
self.fIn = fIn
self.lines = list(lines)
self.lineNr = 0
......@@ -57,7 +57,7 @@ class SimpleMatcher(object):
# if the matcher has weak == true, this matcher should nevel steal
# the matcher can/should repeat immediately
def __init__(self, startReStr, endReStr = None, subMatchers = [], sections = [],
def __init__(self, startReStr, endReStr = None, subMatchers = tuple(), sections = tuple(),
subFlags = SubFlags.Sequenced,
weak = False, # this matcher should not "steal" the position
repeats = False, # this matcher is expected to repeat
......@@ -67,10 +67,10 @@ class SimpleMatcher(object):
forwardMatch = False, # if start match should not eat input, but be forwarded to adHoc and subMatchers
name = "",
adHoc = None,
otherMetaInfo = [], # The metainfos that are later manually added ot the backend
otherMetaInfo = tuple(), # The metainfos that are later manually added ot the backend
fixedStartValues = None,
fixedEndValues = None,
dependencies={},
dependencies = None,
defLine=0,
defFile='',
coverageIgnore=False, # mark line as ignored in coverage analysis
......@@ -82,8 +82,8 @@ class SimpleMatcher(object):
self.index = -1
self.startReStr = startReStr
self.endReStr = endReStr
self.subMatchers = subMatchers
self.sections = sections
self.subMatchers = list(subMatchers)
self.sections = list(sections)
self.subFlags = subFlags
self.weak = weak
self.repeats = repeats
......@@ -92,7 +92,9 @@ class SimpleMatcher(object):
self.forwardMatch = forwardMatch
self.superMatcher = None
self.adHoc = adHoc
self.otherMetaInfo = otherMetaInfo
self.otherMetaInfo = list(otherMetaInfo)
if dependencies is None:
dependencies = {}
self.dependencies = dependencies
self.name = name
self.fixedStartValues = fixedStartValues
......@@ -239,9 +241,12 @@ class SimpleMatcher(object):
groups.extend(extractGroupNames(self.endReStr))
return groups
def allMetaNames(self, metaNames=[]):
def allMetaNames(self, metaNames=None):
"""The names of the meta infos the could be matched by this matcher or its sub matchers.
groups can be a """
if metaNames is None:
metaNames = []
metaNames.extend(self.directMetaNames())
for m in self.subMatchers:
m.allMetaNames(metaNames)
......@@ -1281,20 +1286,20 @@ def defaultParseFile(parserInfo):
def mainFunction(mainFileDescription,
metaInfoEnv,
parserInfo,
parseFile = None,
outF = sys.stdout,
cachingLevelForMetaName = {},
defaultDataCachingLevel = CachingLevel.ForwardAndCache,
defaultSectionCachingLevel = CachingLevel.Forward,
superContext = None,
onClose = {},
onOpen = {},
parseFile=None,
outF=sys.stdout,
cachingLevelForMetaName=None,
defaultDataCachingLevel=CachingLevel.ForwardAndCache,
defaultSectionCachingLevel=CachingLevel.Forward,
superContext=None,
onClose=None,
onOpen=None,
default_units=None,
metainfo_units=None,
superBackend=None,
metaInfoToKeep=None,
mainFile=None,
strValueTransform={}):
strValueTransform=None):
"""
Args:
default_units: A list of default unit definitions.
......@@ -1330,6 +1335,16 @@ def mainFunction(mainFileDescription,
verbose = False
fileToParse = None
writeMatchTelemetry = False
if cachingLevelForMetaName is None:
cachingLevelForMetaName = {}
if onClose is None:
onClose = {}
if onOpen is None:
onOpen = {}
if strValueTransform is None:
strValueTransform = {}
ii = 1
while ii < len(sys.argv):
arg = sys.argv[ii]
......@@ -1531,7 +1546,7 @@ class ParserOptimizer(object):
"""For optimizing a hierarchy of SimpleMatchers based on a list of metainfo
names that should be included in the parsing.
"""
def optimizeParsingTree(self, rootMatcher, metaInfoToKeep=[]):
def optimizeParsingTree(self, rootMatcher, metaInfoToKeep=None):
"""This function will remove any parsing unnecessary parsing actions
from the parsing tree based on the given list of metainfo names to keep
and metainfo names to skip.
......@@ -1542,6 +1557,9 @@ class ParserOptimizer(object):
metaInfoToKeep: List of metainfonames to keep in parsing
"""
# First identify the parts that should be kept
if metaInfoToKeep is None:
metaInfoToKeep = []
if metaInfoToKeep:
# Single values are put inside a list for convenience
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment