pylint/openencoding: Fix checking of nonconst mode
This commit is contained in:
parent
181bcc4f8d
commit
bd3d091318
@ -62,10 +62,16 @@ class OpenEncodingChecker(checkers.BaseChecker):
|
|||||||
except utils.NoSuchArgumentError:
|
except utils.NoSuchArgumentError:
|
||||||
pass
|
pass
|
||||||
if _encoding is None:
|
if _encoding is None:
|
||||||
if mode_arg is not None:
|
if mode_arg is None:
|
||||||
|
mode = None
|
||||||
|
else:
|
||||||
mode = utils.safe_infer(mode_arg)
|
mode = utils.safe_infer(mode_arg)
|
||||||
if (mode_arg is not None and isinstance(mode, astroid.Const) and
|
if mode is not None and not isinstance(mode, astroid.Const):
|
||||||
'b' in getattr(mode, 'value', '')):
|
# We can't say what mode is exactly.
|
||||||
|
return
|
||||||
|
if mode is None:
|
||||||
|
self.add_message('open-without-encoding', node=node)
|
||||||
|
elif 'b' in getattr(mode, 'value', ''):
|
||||||
# Files opened as binary don't need an encoding.
|
# Files opened as binary don't need an encoding.
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user