From bd76d83ad30c2f3e2ecc596bc4df44de2e681b6c Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 17 Jun 2019 17:57:26 -0400 Subject: Use an object instead of a dict for the report data --- coverage/backward.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'coverage/backward.py') diff --git a/coverage/backward.py b/coverage/backward.py index 1d92469d..05fa261e 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -155,6 +155,24 @@ except AttributeError: PYC_MAGIC_NUMBER = imp.get_magic() +try: + from types import SimpleNamespace +except ImportError: + # The code from https://docs.python.org/3/library/types.html#types.SimpleNamespace + class SimpleNamespace: + """Python implementation of SimpleNamespace, for Python 2.""" + def __init__(self, **kwargs): + self.__dict__.update(kwargs) + + def __repr__(self): + keys = sorted(self.__dict__) + items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys) + return "{}({})".format(type(self).__name__, ", ".join(items)) + + def __eq__(self, other): + return self.__dict__ == other.__dict__ + + def invalidate_import_caches(): """Invalidate any import caches that may or may not exist.""" if importlib and hasattr(importlib, "invalidate_caches"): -- cgit v1.2.1