From f4d9e9cb7b47fff4cd01352266fd45d11dc7b48f Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Tue, 10 Aug 2021 17:04:50 -0400 Subject: [PATCH] BUG: __getattr__ must raise AttributeError if name not found PR #20733 added module-level `__getattr__` functions to several modules. All of the functions with the exception of the one in `matplotlib.style.core` had a terminal `raise AttributeError` to handle unmatched attributes. The omission in `matplotlib.style.core` was probably unintentional; it results in confusing and buggy behavior such as: ```pycon >>> import matplotlib.style.core >>> if hasattr(matplotlib.style.core, '__warningregistry__'): ... del matplotlib.style.core.__warningregistry__ ... Traceback (most recent call last): File "", line 2, in AttributeError: __warningregistry__ ``` This causes problems in the unit tests for astropy affiliated packages. See astropy/astropy#12038. --- lib/matplotlib/style/core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/style/core.py b/lib/matplotlib/style/core.py index d0592bd32201..1c5a0d25b739 100644 --- a/lib/matplotlib/style/core.py +++ b/lib/matplotlib/style/core.py @@ -33,6 +33,7 @@ def __getattr__(name): if name == "STYLE_FILE_PATTERN": _api.warn_deprecated("3.5", name=name) return re.compile(r'([\S]+).%s$' % STYLE_EXTENSION) + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") BASE_LIBRARY_PATH = os.path.join(mpl.get_data_path(), 'stylelib')