diff options
author | Matt Clay <matt@mystile.com> | 2022-08-05 07:29:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-05 07:29:38 +0200 |
commit | 85acf4d1e55e95c266a35c49f74af3c0f251de08 (patch) | |
tree | e30d4ad68ac64f342f0c4371c1d76e8b776419b4 /test/lib/ansible_test/_internal/provisioning.py | |
parent | ansible-test - More type hint updates. (#78455) (diff) | |
download | ansible-85acf4d1e55e95c266a35c49f74af3c0f251de08.tar.xz ansible-85acf4d1e55e95c266a35c49f74af3c0f251de08.zip |
ansible-test - Avoid use of deprecated type hints. (#78456)
* ansible-test - Avoid use of deprecated type hints.
PEP 585 deprecated many container types in the `typing` module in favor of the actual types, which support subscripting as of Python 3.9.
Conversion of `t.Type` was skipped since PyCharm does not currently recognize it.
* ansible-test - Fix `t` and `c` imports/shadowing.
Diffstat (limited to 'test/lib/ansible_test/_internal/provisioning.py')
-rw-r--r-- | test/lib/ansible_test/_internal/provisioning.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/test/lib/ansible_test/_internal/provisioning.py b/test/lib/ansible_test/_internal/provisioning.py index b61d69d8c7..42de521d21 100644 --- a/test/lib/ansible_test/_internal/provisioning.py +++ b/test/lib/ansible_test/_internal/provisioning.py @@ -2,6 +2,7 @@ from __future__ import annotations import atexit +import collections.abc as c import dataclasses import functools import itertools @@ -54,10 +55,10 @@ class PrimeContainers(ApplicationError): class HostState: """State of hosts and profiles to be passed to ansible-test during delegation.""" controller_profile: ControllerHostProfile - target_profiles: t.List[HostProfile] + target_profiles: list[HostProfile] @property - def profiles(self) -> t.List[HostProfile]: + def profiles(self) -> list[HostProfile]: """Return all the profiles as a list.""" return [t.cast(HostProfile, self.controller_profile)] + self.target_profiles @@ -79,26 +80,26 @@ class HostState: return host_state - def get_controller_target_connections(self) -> t.List[SshConnection]: + def get_controller_target_connections(self) -> list[SshConnection]: """Return SSH connection(s) for accessing all target hosts from the controller.""" return list(itertools.chain.from_iterable([target.get_controller_target_connections() for target in self.target_profiles if isinstance(target, SshTargetHostProfile)])) - def targets(self, profile_type: t.Type[THostProfile]) -> t.List[THostProfile]: + def targets(self, profile_type: t.Type[THostProfile]) -> list[THostProfile]: """The list of target(s), verified to be of the specified type.""" if not self.target_profiles: raise Exception('No target profiles found.') assert type_guard(self.target_profiles, profile_type) - return t.cast(t.List[THostProfile], self.target_profiles) + return t.cast(list[THostProfile], self.target_profiles) def prepare_profiles( args: TEnvironmentConfig, targets_use_pypi: bool = False, skip_setup: bool = False, - requirements: t.Optional[t.Callable[[TEnvironmentConfig, HostState], None]] = None, + requirements: t.Optional[c.Callable[[TEnvironmentConfig, HostState], None]] = None, ) -> HostState: """ Create new profiles, or load existing ones, and return them. @@ -174,7 +175,7 @@ def cleanup_profiles(host_state: HostState) -> None: profile.deprovision() -def dispatch_jobs(jobs: t.List[t.Tuple[HostProfile, WrappedThread]]) -> None: +def dispatch_jobs(jobs: list[tuple[HostProfile, WrappedThread]]) -> None: """Run the given profile job threads and wait for them to complete.""" for profile, thread in jobs: thread.daemon = True |