1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Avoid types.NoneType

types.NoneType was removed in Python 3.

None is a singleton in Python, so 'x is None' is equivalent to
'isinstance(x, NoneType)'.
This commit is contained in:
Marius Gedminas 2015-08-27 09:25:51 +03:00
parent da1e611b26
commit df1b41d3d3
5 changed files with 8 additions and 14 deletions

View file

@ -245,7 +245,7 @@ def _list_into_cache(regions):
if cs is None: if cs is None:
warnings.warn( warnings.warn(
'Connecting to Rackspace region "%s" has caused Pyrax to ' 'Connecting to Rackspace region "%s" has caused Pyrax to '
'return a NoneType. Is this a valid region?' % region, 'return None. Is this a valid region?' % region,
RuntimeWarning) RuntimeWarning)
continue continue
for server in cs.servers.list(): for server in cs.servers.list():

View file

@ -20,8 +20,6 @@ __metaclass__ = type
import os import os
from types import NoneType
from ansible.errors import AnsibleParserError from ansible.errors import AnsibleParserError
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleSequence from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleSequence

View file

@ -25,7 +25,6 @@ import inspect
import os import os
from hashlib import sha1 from hashlib import sha1
from types import NoneType
from ansible.errors import AnsibleError, AnsibleParserError from ansible.errors import AnsibleError, AnsibleParserError
from ansible.parsing import DataLoader from ansible.parsing import DataLoader
@ -184,16 +183,16 @@ class Role(Base, Become, Conditional, Taggable):
# vars and default vars are regular dictionaries # vars and default vars are regular dictionaries
self._role_vars = self._load_role_yaml('vars') self._role_vars = self._load_role_yaml('vars')
if not isinstance(self._role_vars, (dict, NoneType)): if self._role_vars is None:
raise AnsibleParserError("The vars/main.yml file for role '%s' must contain a dictionary of variables" % self._role_name)
elif self._role_vars is None:
self._role_vars = dict() self._role_vars = dict()
elif not isinstance(self._role_vars, dict):
raise AnsibleParserError("The vars/main.yml file for role '%s' must contain a dictionary of variables" % self._role_name)
self._default_vars = self._load_role_yaml('defaults') self._default_vars = self._load_role_yaml('defaults')
if not isinstance(self._default_vars, (dict, NoneType)): if self._default_vars is None:
raise AnsibleParserError("The default/main.yml file for role '%s' must contain a dictionary of variables" % self._role_name)
elif self._default_vars is None:
self._default_vars = dict() self._default_vars = dict()
elif not isinstance(self._default_vars, dict):
raise AnsibleParserError("The default/main.yml file for role '%s' must contain a dictionary of variables" % self._role_name)
def _load_role_yaml(self, subdir): def _load_role_yaml(self, subdir):
file_path = os.path.join(self._role_path, subdir) file_path = os.path.join(self._role_path, subdir)

View file

@ -19,8 +19,6 @@ __metaclass__ = type
import os import os
from types import NoneType
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
from ansible.parsing import DataLoader from ansible.parsing import DataLoader
from ansible.plugins.action import ActionBase from ansible.plugins.action import ActionBase

View file

@ -37,7 +37,6 @@ from ansible.template.vars import AnsibleJ2Vars
from ansible.utils.debug import debug from ansible.utils.debug import debug
from numbers import Number from numbers import Number
from types import NoneType
__all__ = ['Templar'] __all__ = ['Templar']
@ -188,7 +187,7 @@ class Templar:
resolved_val = self._available_variables[var_name] resolved_val = self._available_variables[var_name]
if isinstance(resolved_val, NON_TEMPLATED_TYPES): if isinstance(resolved_val, NON_TEMPLATED_TYPES):
return resolved_val return resolved_val
elif isinstance(resolved_val, NoneType): elif resolved_val is None:
return C.DEFAULT_NULL_REPRESENTATION return C.DEFAULT_NULL_REPRESENTATION
result = self._do_template(variable, preserve_trailing_newlines=preserve_trailing_newlines, fail_on_undefined=fail_on_undefined, overrides=overrides) result = self._do_template(variable, preserve_trailing_newlines=preserve_trailing_newlines, fail_on_undefined=fail_on_undefined, overrides=overrides)