1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-06-05 15:57:05 +00:00

multiple: replace namedtuple with dataclass (#12094)

* refactor(multiple): replace namedtuple with dataclass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* chore(changelog): add fragment for PR 12094

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Update comment.

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2026-05-26 01:50:34 +12:00 committed by GitHub
parent 850ef03fe7
commit cbc6f6eed3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 47 additions and 20 deletions

View file

@ -88,6 +88,7 @@ running:
import json
import typing as t
from dataclasses import dataclass
from ansible.module_utils.basic import AnsibleModule
@ -97,16 +98,15 @@ from ansible_collections.community.general.plugins.module_utils._homebrew import
)
# Stores validated arguments for an instance of an action.
# See DOCUMENTATION string for argument-specific information.
class HomebrewServiceArgs(t.NamedTuple):
@dataclass
class HomebrewServiceArgs:
name: str
state: str
brew_path: str
# Stores the state of a Homebrew service.
class HomebrewServiceState(t.NamedTuple):
@dataclass
class HomebrewServiceState:
running: bool
pid: int | None

View file

@ -232,11 +232,19 @@ roles:
import os
import time
from collections import namedtuple
from dataclasses import dataclass
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import open_url
@dataclass
class AuthParams:
url: str
user: str
password: str
STATES = (
"PENDING",
"DEPLOYING",
@ -728,9 +736,7 @@ def get_connection_info(module):
module.fail_json(
msg="One or more connection parameters (api_url, api_username, api_password) were not specified"
)
auth_params = namedtuple("auth", ("url", "user", "password"))
return auth_params(url=url, user=username, password=password)
return AuthParams(url=url, user=username, password=password)
def main():

View file

@ -688,13 +688,21 @@ import copy
import os
import re
import time
from collections import namedtuple
from dataclasses import dataclass
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.dict_transformations import dict_merge
from ansible_collections.community.general.plugins.module_utils._opennebula import flatten, render
@dataclass
class AuthParams:
url: str
username: str
password: str
# Updateconf attributes documentation: https://docs.opennebula.io/6.10/integration_and_development/system_interfaces/api.html#one-vm-updateconf
UPDATECONF_ATTRIBUTES = {
"OS": ["ARCH", "MACHINE", "KERNEL", "INITRD", "BOOTLOADER", "BOOT", "SD_DISK_BUS", "UUID", "FIRMWARE"],
@ -1632,9 +1640,7 @@ def get_connection_info(module):
if not url:
module.fail_json(msg="Opennebula API url (api_url) is not specified")
auth_params = namedtuple("auth", ("url", "username", "password"))
return auth_params(url=url, username=username, password=password)
return AuthParams(url=url, username=username, password=password)
def main():

View file

@ -275,7 +275,8 @@ EXAMPLES = r"""
import re
import shlex
from collections import defaultdict, namedtuple
from collections import defaultdict
from dataclasses import dataclass
from ansible.module_utils.basic import AnsibleModule
@ -296,7 +297,10 @@ class Package:
return f'Package("{self.name}", "{self.source}", {self.source_is_URL})'
VersionTuple = namedtuple("VersionTuple", ["current", "latest"])
@dataclass
class VersionTuple:
current: str
latest: str
class Pacman:
@ -717,7 +721,7 @@ class Pacman:
"installed_groups": {groupname: set(pkgnames)},
"available_pkgs": {pkgname: version},
"available_groups": {groupname: set(pkgnames)},
"upgradable_pkgs": {pkgname: (current_version,latest_version)},
"upgradable_pkgs": {pkgname: VersionTuple},
"pkg_reasons": {pkgname: reason},
}