diff options
author | Martin Krizek <martin.krizek@gmail.com> | 2022-10-11 18:16:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-11 18:16:57 +0300 |
commit | 58637702b443b95c9b2e6ae00e529ac8ae86d5ee (patch) | |
tree | 7e6263d18333bc49b4a0f66baf844f96e4d93ac9 | |
parent | 1286b7d42ee9053fa016812eddce40ce40978581 (diff) |
Cache field attributes list on the playbook classes (#79091)
* Cache field attributes list on the playbook classes
-rw-r--r-- | changelogs/fragments/cache-fa-on-pb-cls.yml | 2 | ||||
-rw-r--r-- | lib/ansible/playbook/base.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/changelogs/fragments/cache-fa-on-pb-cls.yml b/changelogs/fragments/cache-fa-on-pb-cls.yml new file mode 100644 index 00000000000..ab06b03559f --- /dev/null +++ b/changelogs/fragments/cache-fa-on-pb-cls.yml @@ -0,0 +1,2 @@ +minor_changes: + - Cache field attributes list on the playbook classes diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index 5504645a126..bf007581308 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -10,6 +10,7 @@ import operator import os from copy import copy as shallowcopy +from functools import cache from jinja2.exceptions import UndefinedError @@ -74,7 +75,14 @@ class FieldAttributeBase: @classmethod @property def fattributes(cls): - # FIXME is this worth caching? + return cls._fattributes() + + # mypy complains with "misc: Decorated property not supported" + # when @property and @cache are used together, + # split fattributes above into two methods + @classmethod + @cache + def _fattributes(cls): fattributes = {} for class_obj in reversed(cls.__mro__): for name, attr in list(class_obj.__dict__.items()): |