Skip to content

Commit 3e4b0d7

Browse files
committed
Remove deprecated use of typing Any, Dict.
This commit removes deprecated type hints Any and Dict from typing. 1. from typing import * statements are removed. 2. function signatures are modified to use the new recommended type hints. While a lot of files are changed, there are no other changes to any of the files.
1 parent 7e64268 commit 3e4b0d7

28 files changed

+142
-187
lines changed

plugins/module_utils/common/merge_dicts.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import inspect
2323
import logging
2424
from collections.abc import MutableMapping as Map
25-
from typing import Any, Dict
2625

2726

2827
class MergeDicts:
@@ -78,9 +77,7 @@ def commit(self) -> None:
7877

7978
self.properties["dict_merged"] = self.merge_dicts(self.dict1, self.dict2)
8079

81-
def merge_dicts(
82-
self, dict1: Dict[Any, Any], dict2: Dict[Any, Any]
83-
) -> Dict[Any, Any]:
80+
def merge_dicts(self, dict1: dict, dict2: dict) -> dict:
8481
"""
8582
Merge dict2 into dict1 and return dict1.
8683
Keys in dict2 have precedence over keys in dict1.

plugins/module_utils/common/merge_dicts_v2.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import inspect
2323
import logging
2424
from collections.abc import MutableMapping as Map
25-
from typing import Any, Dict
2625

2726

2827
class MergeDicts:
@@ -90,9 +89,7 @@ def commit(self) -> None:
9089

9190
self.properties["dict_merged"] = self.merge_dicts(self.dict1, self.dict2)
9291

93-
def merge_dicts(
94-
self, dict1: Dict[Any, Any], dict2: Dict[Any, Any]
95-
) -> Dict[Any, Any]:
92+
def merge_dicts(self, dict1: dict, dict2: dict) -> dict:
9693
"""
9794
Merge dict2 into dict1 and return dict1.
9895
Keys in dict2 have precedence over keys in dict1.

plugins/module_utils/common/params_merge_defaults.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import inspect
2323
import logging
2424
from collections.abc import MutableMapping as Map
25-
from typing import Any, Dict
2625

2726

2827
class ParamsMergeDefaults:
@@ -75,9 +74,7 @@ def _build_reserved_params(self):
7574
self.reserved_params.add("type")
7675
self.reserved_params.add("preferred_type")
7776

78-
def _merge_default_params(
79-
self, spec: Dict[str, Any], params: Dict[str, Any]
80-
) -> Dict[str, Any]:
77+
def _merge_default_params(self, spec: dict, params: dict) -> dict:
8178
"""
8279
Merge default parameters into parameters.
8380

plugins/module_utils/common/params_merge_defaults_v2.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import inspect
2323
import logging
2424
from collections.abc import MutableMapping as Map
25-
from typing import Any, Dict
2625

2726

2827
class ParamsMergeDefaults:
@@ -84,9 +83,7 @@ def _build_reserved_params(self):
8483
self.reserved_params.add("type")
8584
self.reserved_params.add("preferred_type")
8685

87-
def _merge_default_params(
88-
self, spec: Dict[str, Any], params: Dict[str, Any]
89-
) -> Dict[str, Any]:
86+
def _merge_default_params(self, spec: dict, params: dict) -> dict:
9087
"""
9188
### Summary
9289
Merge default parameters into parameters.

plugins/module_utils/common/params_validate.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import ipaddress
2323
import logging
2424
from collections.abc import MutableMapping as Map
25-
from typing import Any, List
2625

2726
from ansible.module_utils.common import validation
2827

@@ -53,7 +52,7 @@ class ParamsValidate:
5352
- ``bar`` can be assigned one of three values: bingo, bango, or bongo.
5453
5554
```python
56-
params_spec: Dict[str, Any] = {}
55+
params_spec: dict = {}
5756
params_spec["ip_address"] = {}
5857
params_spec["ip_address"]["required"] = False
5958
params_spec["ip_address"]["type"] = "ipv4"
@@ -270,7 +269,7 @@ def _validate_parameters(self, spec, parameters):
270269
param,
271270
)
272271

273-
def _verify_choices(self, choices: List[Any], value: Any, param: str) -> None:
272+
def _verify_choices(self, choices: list, value, param: str) -> None:
274273
"""
275274
Verify that value is one of the choices
276275
"""
@@ -309,7 +308,7 @@ def _verify_integer_range(
309308
msg += f"Got {value}"
310309
self.ansible_module.fail_json(msg)
311310

312-
def _verify_type(self, expected_type: str, params: Any, param: str) -> Any:
311+
def _verify_type(self, expected_type: str, params, param: str):
313312
"""
314313
Verify that value's type matches the expected type
315314
"""
@@ -330,7 +329,7 @@ def _verify_type(self, expected_type: str, params: Any, param: str) -> Any:
330329
self._invalid_type(expected_type, value, param, err)
331330
return value
332331

333-
def _ipaddress_guard(self, expected_type, value: Any, param: str) -> None:
332+
def _ipaddress_guard(self, expected_type, value, param: str) -> None:
334333
"""
335334
Guard against int and bool types for ipv4, ipv6, ipv4_subnet,
336335
and ipv6_subnet type.
@@ -357,7 +356,7 @@ def _ipaddress_guard(self, expected_type, value: Any, param: str) -> None:
357356
raise TypeError(f"{msg}")
358357

359358
def _invalid_type(
360-
self, expected_type: str, value: Any, param: str, error: str = ""
359+
self, expected_type: str, value, param: str, error: str = ""
361360
) -> None:
362361
"""
363362
Calls fail_json when value's type does not match expected_type
@@ -371,8 +370,8 @@ def _invalid_type(
371370
self.ansible_module.fail_json(msg)
372371

373372
def _verify_multitype( # pylint: disable=inconsistent-return-statements
374-
self, spec: Any, params: Any, param: str
375-
) -> Any:
373+
self, spec, params, param: str
374+
):
376375
"""
377376
Verify that value's type matches one of the types in expected_types
378377
@@ -427,7 +426,7 @@ def _verify_multitype( # pylint: disable=inconsistent-return-statements
427426
self.ansible_module.fail_json(msg)
428427

429428
def _verify_preferred_type_param_spec_is_present(
430-
self, spec: Any, param: str
429+
self, spec, param: str
431430
) -> None:
432431
"""
433432
verify that spec contains the key 'preferred_type'
@@ -440,7 +439,7 @@ def _verify_preferred_type_param_spec_is_present(
440439
self.ansible_module.fail_json(msg)
441440

442441
def _verify_preferred_type_for_standard_types(
443-
self, preferred_type: str, value: Any
442+
self, preferred_type: str, value
444443
) -> tuple:
445444
"""
446445
If preferred_type is one of the standard python types
@@ -461,7 +460,7 @@ def _verify_preferred_type_for_standard_types(
461460
return (False, value)
462461

463462
def _verify_preferred_type_for_ipaddress_types(
464-
self, preferred_type: str, value: Any
463+
self, preferred_type: str, value
465464
) -> tuple:
466465
"""
467466
We can't use isinstance() to verify ipaddress types.
@@ -479,7 +478,7 @@ def _verify_preferred_type_for_ipaddress_types(
479478
return (False, value)
480479

481480
@staticmethod
482-
def _validate_ipv4_address(value: Any) -> Any:
481+
def _validate_ipv4_address(value):
483482
"""
484483
verify that value is an IPv4 address
485484
"""
@@ -490,7 +489,7 @@ def _validate_ipv4_address(value: Any) -> Any:
490489
raise ValueError(f"invalid IPv4 address: {err}") from err
491490

492491
@staticmethod
493-
def _validate_ipv4_subnet(value: Any) -> Any:
492+
def _validate_ipv4_subnet(value):
494493
"""
495494
verify that value is an IPv4 network
496495
"""
@@ -501,7 +500,7 @@ def _validate_ipv4_subnet(value: Any) -> Any:
501500
raise ValueError(f"invalid IPv4 network: {err}") from err
502501

503502
@staticmethod
504-
def _validate_ipv6_address(value: Any) -> Any:
503+
def _validate_ipv6_address(value):
505504
"""
506505
verify that value is an IPv6 address
507506
"""
@@ -512,7 +511,7 @@ def _validate_ipv6_address(value: Any) -> Any:
512511
raise ValueError(f"invalid IPv6 address: {err}") from err
513512

514513
@staticmethod
515-
def _validate_ipv6_subnet(value: Any) -> Any:
514+
def _validate_ipv6_subnet(value):
516515
"""
517516
verify that value is an IPv6 network
518517
"""
@@ -523,7 +522,7 @@ def _validate_ipv6_subnet(value: Any) -> Any:
523522
raise ValueError(f"invalid IPv6 network: {err}") from err
524523

525524
@staticmethod
526-
def _validate_set(value: Any) -> Any:
525+
def _validate_set(value):
527526
"""
528527
verify that value is a set
529528
"""
@@ -532,7 +531,7 @@ def _validate_set(value: Any) -> Any:
532531
return value
533532

534533
@staticmethod
535-
def _validate_tuple(value: Any) -> Any:
534+
def _validate_tuple(value):
536535
"""
537536
verify that value is a tuple
538537
"""

plugins/module_utils/common/params_validate_v2.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import ipaddress
2323
import logging
2424
from collections.abc import MutableMapping as Map
25-
from typing import Any, List
2625

2726
from ansible.module_utils.common import validation
2827

@@ -48,7 +47,7 @@ class ParamsValidate:
4847
- ``bar`` can be assigned one of three values: bingo, bango, or bongo.
4948
5049
```python
51-
params_spec: Dict[str, Any] = {}
50+
params_spec: dict = {}
5251
params_spec["ip_address"] = {}
5352
params_spec["ip_address"]["required"] = False
5453
params_spec["ip_address"]["type"] = "ipv4"
@@ -300,7 +299,7 @@ def _validate_parameters(self, spec, parameters):
300299
except (TypeError, ValueError) as error:
301300
raise ValueError(error) from error
302301

303-
def _verify_choices(self, choices: List[Any], value: Any, param: str) -> None:
302+
def _verify_choices(self, choices: list, value, param: str) -> None:
304303
"""
305304
### Summary
306305
Verify that value is one of the choices
@@ -351,7 +350,7 @@ def _verify_integer_range(
351350
msg += f"Got {value}"
352351
raise ValueError(msg)
353352

354-
def _verify_type(self, expected_type: str, params: Any, param: str):
353+
def _verify_type(self, expected_type: str, params, param: str):
355354
"""
356355
### Summary
357356
Verify that value's type matches the expected type
@@ -384,7 +383,7 @@ def _verify_type(self, expected_type: str, params: Any, param: str):
384383

385384
return return_value
386385

387-
def _ipaddress_guard(self, expected_type, value: Any, param: str) -> None:
386+
def _ipaddress_guard(self, expected_type, value, param: str) -> None:
388387
"""
389388
### Summary
390389
Guard against int and bool types for ipv4, ipv6, ipv4_subnet,
@@ -414,7 +413,7 @@ def _ipaddress_guard(self, expected_type, value: Any, param: str) -> None:
414413
raise TypeError(msg)
415414

416415
def _invalid_type(
417-
self, expected_type: str, value: Any, param: str, error: str = ""
416+
self, expected_type: str, value, param: str, error: str = ""
418417
) -> None:
419418
"""
420419
### Summary
@@ -431,9 +430,7 @@ def _invalid_type(
431430
msg += f"Error detail: {error}"
432431
raise TypeError(msg)
433432

434-
def _verify_multitype( # pylint: disable=inconsistent-return-statements
435-
self, spec: Any, params: Any, param: str
436-
) -> Any:
433+
def _verify_multitype(self, spec, params, param: str):
437434
"""
438435
### Summary
439436
Verify that value's type matches one of the types in expected_types
@@ -448,6 +445,7 @@ def _verify_multitype( # pylint: disable=inconsistent-return-statements
448445
1. We've disabled inconsistent-return-statements. We're pretty
449446
sure this method is correct.
450447
"""
448+
# pylint: disable=inconsistent-return-statements
451449
method_name = inspect.stack()[0][3]
452450

453451
# preferred_type is mandatory for multitype
@@ -497,9 +495,7 @@ def _verify_multitype( # pylint: disable=inconsistent-return-statements
497495
msg += f"Got '{value}'."
498496
raise TypeError(msg)
499497

500-
def _verify_preferred_type_param_spec_is_present(
501-
self, spec: Any, param: str
502-
) -> None:
498+
def _verify_preferred_type_param_spec_is_present(self, spec, param: str) -> None:
503499
"""
504500
### Summary
505501
Verify that spec contains the key 'preferred_type'
@@ -515,7 +511,7 @@ def _verify_preferred_type_param_spec_is_present(
515511
raise KeyError(msg)
516512

517513
def _verify_preferred_type_for_standard_types(
518-
self, preferred_type: str, value: Any
514+
self, preferred_type: str, value
519515
) -> tuple:
520516
"""
521517
If preferred_type is one of the standard python types
@@ -536,7 +532,7 @@ def _verify_preferred_type_for_standard_types(
536532
return (False, value)
537533

538534
def _verify_preferred_type_for_ipaddress_types(
539-
self, preferred_type: str, value: Any
535+
self, preferred_type: str, value
540536
) -> tuple:
541537
"""
542538
We can't use isinstance() to verify ipaddress types.
@@ -554,7 +550,7 @@ def _verify_preferred_type_for_ipaddress_types(
554550
return (False, value)
555551

556552
@staticmethod
557-
def _validate_ipv4_address(value: Any) -> Any:
553+
def _validate_ipv4_address(value):
558554
"""
559555
verify that value is an IPv4 address
560556
"""
@@ -565,7 +561,7 @@ def _validate_ipv4_address(value: Any) -> Any:
565561
raise ValueError(f"invalid IPv4 address: {err}") from err
566562

567563
@staticmethod
568-
def _validate_ipv4_subnet(value: Any) -> Any:
564+
def _validate_ipv4_subnet(value):
569565
"""
570566
verify that value is an IPv4 network
571567
"""
@@ -576,7 +572,7 @@ def _validate_ipv4_subnet(value: Any) -> Any:
576572
raise ValueError(f"invalid IPv4 network: {err}") from err
577573

578574
@staticmethod
579-
def _validate_ipv6_address(value: Any) -> Any:
575+
def _validate_ipv6_address(value):
580576
"""
581577
verify that value is an IPv6 address
582578
"""
@@ -587,7 +583,7 @@ def _validate_ipv6_address(value: Any) -> Any:
587583
raise ValueError(f"invalid IPv6 address: {err}") from err
588584

589585
@staticmethod
590-
def _validate_ipv6_subnet(value: Any) -> Any:
586+
def _validate_ipv6_subnet(value):
591587
"""
592588
verify that value is an IPv6 network
593589
"""
@@ -598,7 +594,7 @@ def _validate_ipv6_subnet(value: Any) -> Any:
598594
raise ValueError(f"invalid IPv6 network: {err}") from err
599595

600596
@staticmethod
601-
def _validate_set(value: Any) -> Any:
597+
def _validate_set(value):
602598
"""
603599
verify that value is a set
604600
"""
@@ -607,7 +603,7 @@ def _validate_set(value: Any) -> Any:
607603
return value
608604

609605
@staticmethod
610-
def _validate_tuple(value: Any) -> Any:
606+
def _validate_tuple(value):
611607
"""
612608
verify that value is a tuple
613609
"""

0 commit comments

Comments
 (0)