Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated stacked @classmethod and @property #79952

Merged
merged 3 commits into from Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/no-stacked-descriptors.yaml
@@ -0,0 +1,2 @@
minor_changes:
- Playbook objects - Replace deprecated stacked ``@classmethod`` and ``@property``
16 changes: 9 additions & 7 deletions lib/ansible/playbook/base.py
Expand Up @@ -70,16 +70,18 @@ def _validate_action_group_metadata(action, found_group_metadata, fq_group_name)
display.warning(" ".join(metadata_warnings))


class _ClassProperty:
def __set_name__(self, owner, name):
self.name = name

def __get__(self, obj, objtype=None):
return getattr(objtype, f'_{self.name}')()


class FieldAttributeBase:

@classmethod # type: ignore[misc]
@property
def fattributes(cls):
return cls._fattributes()
fattributes = _ClassProperty()

# 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):
Expand Down