diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-11-08 18:32:40 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-11-08 18:32:40 (GMT) |
commit | 6672ea942447f409871bd19c928521be13aae1e5 (patch) | |
tree | d80463f40fc3f9ddae700b44730ef53eb4f5ce6f /Lib/trace.py | |
parent | 551f02ca630ad68a8797a8949e83bfc31c3f4cbf (diff) | |
download | cpython-6672ea942447f409871bd19c928521be13aae1e5.zip cpython-6672ea942447f409871bd19c928521be13aae1e5.tar.gz cpython-6672ea942447f409871bd19c928521be13aae1e5.tar.bz2 |
Streamlined code in trace.Ignore and added unit tests.
Diffstat (limited to 'Lib/trace.py')
-rw-r--r-- | Lib/trace.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/Lib/trace.py b/Lib/trace.py index d460cf2..8ea4b89 100644 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -128,11 +128,10 @@ PRAGMA_NOCOVER = "#pragma NO COVER" rx_blank = re.compile(r'^\s*(#.*)?$') class Ignore: - def __init__(self, modules = None, dirs = None): - self._mods = modules or [] - self._dirs = dirs or [] - - self._dirs = list(map(os.path.normpath, self._dirs)) + def __init__(self, modules=None, dirs=None): + self._mods = set() if not modules else set(modules) + self._dirs = [] if not dirs else [os.path.normpath(d) + for d in dirs] self._ignore = { '<string>': 1 } def names(self, filename, modulename): @@ -140,24 +139,22 @@ class Ignore: return self._ignore[modulename] # haven't seen this one before, so see if the module name is - # on the ignore list. Need to take some care since ignoring - # "cmp" musn't mean ignoring "cmpcache" but ignoring - # "Spam" must also mean ignoring "Spam.Eggs". + # on the ignore list. + if modulename in self._mods: # Identical names, so ignore + self._ignore[modulename] = 1 + return 1 + + # check if the module is a proper submodule of something on + # the ignore list for mod in self._mods: - if mod == modulename: # Identical names, so ignore - self._ignore[modulename] = 1 - return 1 - # check if the module is a proper submodule of something on - # the ignore list - n = len(mod) - # (will not overflow since if the first n characters are the - # same and the name has not already occurred, then the size - # of "name" is greater than that of "mod") - if mod == modulename[:n] and modulename[n] == '.': + # Need to take some care since ignoring + # "cmp" mustn't mean ignoring "cmpcache" but ignoring + # "Spam" must also mean ignoring "Spam.Eggs". + if modulename.startswith(mod + '.'): self._ignore[modulename] = 1 return 1 - # Now check that __file__ isn't in one of the directories + # Now check that filename isn't in one of the directories if filename is None: # must be a built-in, so we must ignore self._ignore[modulename] = 1 |