diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2022-05-03 20:24:20 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-05-03 20:24:20 +0000 |
commit | 0cb54010d86493168cc763b836c0a71429b26c1b (patch) | |
tree | 583b489242564e78efe0b2519723e094b057ea14 /lib/sqlalchemy/util/langhelpers.py | |
parent | 675c3e17f7fcccb7534c46adb56529fc3ddd8dbf (diff) | |
parent | 1fa3e2e3814b4d28deca7426bb3f36e7fb515496 (diff) | |
download | sqlalchemy-0cb54010d86493168cc763b836c0a71429b26c1b.tar.gz |
Merge "pep484: attributes and related" into main
Diffstat (limited to 'lib/sqlalchemy/util/langhelpers.py')
-rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 10110dbbe..24c66bfa4 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -1272,17 +1272,20 @@ class MemoizedSlots: def _fallback_getattr(self, key): raise AttributeError(key) - def __getattr__(self, key): + def __getattr__(self, key: str) -> Any: if key.startswith("_memoized_attr_") or key.startswith( "_memoized_method_" ): raise AttributeError(key) - elif hasattr(self, "_memoized_attr_%s" % key): - value = getattr(self, "_memoized_attr_%s" % key)() + # to avoid recursion errors when interacting with other __getattr__ + # schemes that refer to this one, when testing for memoized method + # look at __class__ only rather than going into __getattr__ again. + elif hasattr(self.__class__, f"_memoized_attr_{key}"): + value = getattr(self, f"_memoized_attr_{key}")() setattr(self, key, value) return value - elif hasattr(self, "_memoized_method_%s" % key): - fn = getattr(self, "_memoized_method_%s" % key) + elif hasattr(self.__class__, f"_memoized_method_{key}"): + fn = getattr(self, f"_memoized_method_{key}") def oneshot(*args, **kw): result = fn(*args, **kw) |