mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Remove uses of assert in production code (#32079)
* Remove uses of assert in production code * Fix assertion * Add code smell test for assertions, currently limited to lib/ansible * Fix assertion * Add docs for no-assert * Remove new assert from enos * Fix assert in module_utils.connection
This commit is contained in:
parent
464ded80f5
commit
99d4f5bab4
38 changed files with 195 additions and 89 deletions
|
@ -22,7 +22,7 @@ __metaclass__ = type
|
|||
import collections
|
||||
import os
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleParserError
|
||||
from ansible.errors import AnsibleError, AnsibleParserError, AnsibleAssertionError
|
||||
from ansible.module_utils.six import iteritems, binary_type, text_type
|
||||
from ansible.playbook.attribute import FieldAttribute
|
||||
from ansible.playbook.base import Base
|
||||
|
@ -293,7 +293,8 @@ class Role(Base, Become, Conditional, Taggable):
|
|||
|
||||
def add_parent(self, parent_role):
|
||||
''' adds a role to the list of this roles parents '''
|
||||
assert isinstance(parent_role, Role)
|
||||
if not isinstance(parent_role, Role):
|
||||
raise AnsibleAssertionError()
|
||||
|
||||
if parent_role not in self._parents:
|
||||
self._parents.append(parent_role)
|
||||
|
|
|
@ -22,7 +22,7 @@ __metaclass__ = type
|
|||
import os
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.errors import AnsibleError, AnsibleAssertionError
|
||||
from ansible.module_utils.six import iteritems, string_types
|
||||
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping
|
||||
from ansible.playbook.attribute import Attribute, FieldAttribute
|
||||
|
@ -72,7 +72,8 @@ class RoleDefinition(Base, Become, Conditional, Taggable):
|
|||
if isinstance(ds, int):
|
||||
ds = "%s" % ds
|
||||
|
||||
assert isinstance(ds, dict) or isinstance(ds, string_types) or isinstance(ds, AnsibleBaseYAMLObject)
|
||||
if not isinstance(ds, dict) and not isinstance(ds, string_types) and not isinstance(ds, AnsibleBaseYAMLObject):
|
||||
raise AnsibleAssertionError()
|
||||
|
||||
if isinstance(ds, dict):
|
||||
ds = super(RoleDefinition, self).preprocess_data(ds)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue