From 283a485b9ffbed819b3c6986d4855265fcf43343 Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Thu, 4 Feb 2021 20:35:27 -0500 Subject: [PATCH 1/3] Don't fail when docstrings have been stripped by -OO mode Fixes #2470 --- seaborn/_docstrings.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/seaborn/_docstrings.py b/seaborn/_docstrings.py index 379fa44f96..5db62c0b98 100644 --- a/seaborn/_docstrings.py +++ b/seaborn/_docstrings.py @@ -27,7 +27,18 @@ def __getattr__(self, attr): if attr in self.entries: return self.entries[attr] else: - return self.__getattribute__(attr) + try: + return self.__getattribute__(attr) + except AttributeError as err: + # If Python is run with -OO, it will strip docstrings and our lookup + # from self.entries will fail. We check for __debug__, which is actually + # set to False by -O (it is True for normal execution). + # But we only really want to see an error when building the docs, it's + # not an error so this slight inconsistency is fine. + if __debug__: + raise err + else: + pass @classmethod def from_nested_components(cls, **kwargs): From 9c39d87f13a51089850cb0385a7406895f039e2c Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Fri, 5 Feb 2021 08:33:38 -0500 Subject: [PATCH 2/3] Fix comment --- seaborn/_docstrings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seaborn/_docstrings.py b/seaborn/_docstrings.py index 5db62c0b98..00a6722e10 100644 --- a/seaborn/_docstrings.py +++ b/seaborn/_docstrings.py @@ -33,8 +33,8 @@ def __getattr__(self, attr): # If Python is run with -OO, it will strip docstrings and our lookup # from self.entries will fail. We check for __debug__, which is actually # set to False by -O (it is True for normal execution). - # But we only really want to see an error when building the docs, it's - # not an error so this slight inconsistency is fine. + # But we only want to see an error when building the docs; + # not something users should see, so this slight inconsistency is fine. if __debug__: raise err else: From 250a6439c71782b952c356972b9ac6ddceff6293 Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Fri, 5 Feb 2021 09:08:38 -0500 Subject: [PATCH 3/3] Clarify language --- seaborn/_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaborn/_docstrings.py b/seaborn/_docstrings.py index 00a6722e10..2ab210b6ff 100644 --- a/seaborn/_docstrings.py +++ b/seaborn/_docstrings.py @@ -23,7 +23,7 @@ def __init__(self, comp_dict, strip_whitespace=True): self.entries = entries def __getattr__(self, attr): - """Provided dot access to entries.""" + """Provide dot access to entries for clean raw docstrings.""" if attr in self.entries: return self.entries[attr] else: