8000 BUG: __getattr__ must raise AttributeError if name not found · r03ert0/matplotlib@f4d9e9c · GitHub
[go: up one dir, main page]

Skip to content

Commit f4d9e9c

Browse files
committed
BUG: __getattr__ must raise AttributeError if name not found
PR matplotlib#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 "<stdin>", line 2, in <module> AttributeError: __warningregistry__ ``` This causes problems in the unit tests for astropy affiliated packages. See astropy/astropy#12038.
1 parent b61e76a commit f4d9e9c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/matplotlib/style/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __getattr__(name):
3333
if name == "STYLE_FILE_PATTERN":
3434
_api.warn_deprecated("3.5", name=name)
3535
return re.compile(r'([\S]+).%s$' % STYLE_EXTENSION)
36+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
3637

3738

3839
BASE_LIBRARY_PATH = os.path.join(mpl.get_data_path(), 'stylelib')

0 commit comments

Comments
 (0)
0