mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-25 18:55:20 -06:00
Use isinstance(x, y) instead of type(x) == y
Fixes pylint C0123.
This commit is contained in:
parent
dc4a9f4fff
commit
3ef85739e3
@ -52,7 +52,7 @@ class YamlLintConfig(object):
|
||||
assert isinstance(base_config, YamlLintConfig)
|
||||
|
||||
for rule in self.rules:
|
||||
if (type(self.rules[rule]) == dict and
|
||||
if (isinstance(self.rules[rule], dict) and
|
||||
rule in base_config.rules and
|
||||
base_config.rules[rule] is not False):
|
||||
base_config.rules[rule].update(self.rules[rule])
|
||||
@ -70,7 +70,7 @@ class YamlLintConfig(object):
|
||||
except Exception as e:
|
||||
raise YamlLintConfigError('invalid config: %s' % e)
|
||||
|
||||
if type(conf) != dict:
|
||||
if not isinstance(conf, dict):
|
||||
raise YamlLintConfigError('invalid config: not a dict')
|
||||
|
||||
self.rules = conf.get('rules', {})
|
||||
@ -85,7 +85,7 @@ class YamlLintConfig(object):
|
||||
raise YamlLintConfigError('invalid config: %s' % e)
|
||||
|
||||
if 'ignore' in conf:
|
||||
if type(conf['ignore']) != str:
|
||||
if not isinstance(conf['ignore'], str):
|
||||
raise YamlLintConfigError(
|
||||
'invalid config: ignore should contain file patterns')
|
||||
self.ignore = pathspec.PathSpec.from_lines(
|
||||
@ -107,10 +107,10 @@ def validate_rule_conf(rule, conf):
|
||||
elif conf == 'enable':
|
||||
conf = {}
|
||||
|
||||
if type(conf) == dict:
|
||||
if isinstance(conf, dict):
|
||||
if ('ignore' in conf and
|
||||
type(conf['ignore']) != pathspec.pathspec.PathSpec):
|
||||
if type(conf['ignore']) != str:
|
||||
not isinstance(conf['ignore'], pathspec.pathspec.PathSpec)):
|
||||
if not isinstance(conf['ignore'], str):
|
||||
raise YamlLintConfigError(
|
||||
'invalid config: ignore should contain file patterns')
|
||||
conf['ignore'] = pathspec.PathSpec.from_lines(
|
||||
@ -130,14 +130,14 @@ def validate_rule_conf(rule, conf):
|
||||
raise YamlLintConfigError(
|
||||
'invalid config: unknown option "%s" for rule "%s"' %
|
||||
(optkey, rule.ID))
|
||||
if type(options[optkey]) == tuple:
|
||||
if isinstance(options[optkey], tuple):
|
||||
if (conf[optkey] not in options[optkey] and
|
||||
type(conf[optkey]) not in options[optkey]):
|
||||
raise YamlLintConfigError(
|
||||
'invalid config: option "%s" of "%s" should be in %s'
|
||||
% (optkey, rule.ID, options[optkey]))
|
||||
else:
|
||||
if type(conf[optkey]) != options[optkey]:
|
||||
if not isinstance(conf[optkey], options[optkey]):
|
||||
raise YamlLintConfigError(
|
||||
'invalid config: option "%s" of "%s" should be %s'
|
||||
% (optkey, rule.ID, options[optkey].__name__))
|
||||
|
@ -226,7 +226,7 @@ def run(input, conf, filepath=None):
|
||||
if conf.is_file_ignored(filepath):
|
||||
return ()
|
||||
|
||||
if type(input) in (type(b''), type(u'')): # compat with Python 2 & 3
|
||||
if isinstance(input, (type(b''), type(u''))): # compat with Python 2 & 3
|
||||
return _run(input, conf, filepath)
|
||||
elif hasattr(input, 'read'): # Python 2's file or Python 3's io.IOBase
|
||||
# We need to have everything in memory to parse correctly
|
||||
|
@ -86,14 +86,16 @@ CONF = {'present': bool}
|
||||
|
||||
def check(conf, token, prev, next, nextnext, context):
|
||||
if conf['present']:
|
||||
if (isinstance(token, yaml.StreamEndToken) and
|
||||
not (isinstance(prev, yaml.DocumentEndToken) or
|
||||
isinstance(prev, yaml.StreamStartToken))):
|
||||
is_stream_end = isinstance(token, yaml.StreamEndToken)
|
||||
is_start = isinstance(token, yaml.DocumentStartToken)
|
||||
prev_is_end_or_stream_start = isinstance(
|
||||
prev, (yaml.DocumentEndToken, yaml.StreamStartToken)
|
||||
)
|
||||
|
||||
if is_stream_end and not prev_is_end_or_stream_start:
|
||||
yield LintProblem(token.start_mark.line, 1,
|
||||
'missing document end "..."')
|
||||
elif (isinstance(token, yaml.DocumentStartToken) and
|
||||
not (isinstance(prev, yaml.DocumentEndToken) or
|
||||
isinstance(prev, yaml.StreamStartToken))):
|
||||
elif is_start and not prev_is_end_or_stream_start:
|
||||
yield LintProblem(token.start_mark.line + 1, 1,
|
||||
'missing document end "..."')
|
||||
|
||||
|
@ -224,7 +224,7 @@ def check_scalar_indentation(conf, token, context):
|
||||
|
||||
def compute_expected_indent(found_indent):
|
||||
def detect_indent(base_indent):
|
||||
if type(context['spaces']) is not int:
|
||||
if not isinstance(context['spaces'], int):
|
||||
context['spaces'] = found_indent - base_indent
|
||||
return base_indent + context['spaces']
|
||||
|
||||
@ -312,7 +312,7 @@ def _check(conf, token, prev, next, nextnext, context):
|
||||
token.start_mark.line + 1 > context['cur_line'])
|
||||
|
||||
def detect_indent(base_indent, next):
|
||||
if type(context['spaces']) is not int:
|
||||
if not isinstance(context['spaces'], int):
|
||||
context['spaces'] = next.start_mark.column - base_indent
|
||||
return base_indent + context['spaces']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user