Commit df1b41d3 by Marius Gedminas

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)'.
parent da1e611b
...@@ -245,7 +245,7 @@ def _list_into_cache(regions): ...@@ -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():
......
...@@ -20,8 +20,6 @@ __metaclass__ = type ...@@ -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
......
...@@ -25,7 +25,6 @@ import inspect ...@@ -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): ...@@ -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)
......
...@@ -19,8 +19,6 @@ __metaclass__ = type ...@@ -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
......
...@@ -37,7 +37,6 @@ from ansible.template.vars import AnsibleJ2Vars ...@@ -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: ...@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment