Use classproperty to access field attributes of a class (#78180)

* Use classproperty to access field attributes of a class, consolidate into one class
pull/78320/head
Martin Krizek 2 years ago committed by GitHub
parent 884244f1b2
commit b56b38b3ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- Utilize @classmethod and @property together to form classproperty (Python 3.9) to access field attributes of a class

@ -69,9 +69,9 @@ def _validate_action_group_metadata(action, found_group_metadata, fq_group_name)
display.warning(" ".join(metadata_warnings))
# FIXME use @property and @classmethod together which is possible since Python 3.9
class _FABMeta(type):
class FieldAttributeBase:
@classmethod
@property
def fattributes(cls):
# FIXME is this worth caching?
@ -86,14 +86,6 @@ class _FABMeta(type):
fattributes[attr.alias] = attr
return fattributes
class FieldAttributeBase(metaclass=_FABMeta):
# FIXME use @property and @classmethod together which is possible since Python 3.9
@property
def fattributes(self):
return self.__class__.fattributes
def __init__(self):
# initialize the data loader and variable manager, which will be provided

@ -488,7 +488,7 @@ class TestBaseSubClass(TestBase):
def test_attr_class_post_validate_class_not_instance(self):
not_a_esc = ExampleSubClass
ds = {'test_attr_class_post_validate': not_a_esc}
self.assertRaisesRegex(AnsibleParserError, 'is not a valid.*got a.*Meta.*instead',
self.assertRaisesRegex(AnsibleParserError, "is not a valid.*got a <class 'type'> instead",
self._base_validate, ds)
def test_attr_class_post_validate_wrong_class(self):

Loading…
Cancel
Save