Skip to content

Commit

Permalink
Fix crash when open is called with an integer mode (#6415)
Browse files Browse the repository at this point in the history
Closes #6414
  • Loading branch information
Pierre-Sassoulas committed May 2, 2022
1 parent 3b2fbae commit f1d930b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -20,6 +20,10 @@ What's New in Pylint 2.13.8?
============================
Release date: TBA

* Fix a crash when linting a file that passes an integer ``mode=`` to
``open``

Closes #6414


What's New in Pylint 2.13.7?
Expand Down
5 changes: 5 additions & 0 deletions doc/whatsnew/2.13.rst
Expand Up @@ -610,3 +610,8 @@ Other Changes
* Only raise ``not-callable`` when all the inferred values of a property are not callable.

Closes #5931

* Fix a crash when linting a file that passes an integer ``mode=`` to
``open``

Closes #6414
2 changes: 1 addition & 1 deletion pylint/checkers/stdlib.py
Expand Up @@ -664,7 +664,7 @@ def _check_open_encoded(self, node: nodes.Call, open_module: str) -> None:
if (
not mode_arg
or isinstance(mode_arg, nodes.Const)
and (not mode_arg.value or "b" not in mode_arg.value)
and (not mode_arg.value or "b" not in str(mode_arg.value))
):
encoding_arg = None
try:
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/u/unspecified_encoding_py38.py
Expand Up @@ -159,3 +159,6 @@ class IOArgs:

# Test for crash reported in https://github.com/PyCQA/pylint/issues/5731
open(FILENAME, mode=None) # [bad-open-mode, unspecified-encoding]

# Test for crash reported in https://github.com/PyCQA/pylint/issues/6414
open('foo', mode=2) # [bad-open-mode, unspecified-encoding]
2 changes: 2 additions & 0 deletions tests/functional/u/unspecified_encoding_py38.txt
Expand Up @@ -29,3 +29,5 @@ unspecified-encoding:155:0:155:26::Using open without explicitly specifying an e
unspecified-encoding:158:0:158:35::Using open without explicitly specifying an encoding:UNDEFINED
bad-open-mode:161:0:161:25::"""None"" is not a valid mode for open.":UNDEFINED
unspecified-encoding:161:0:161:25::Using open without explicitly specifying an encoding:UNDEFINED
bad-open-mode:164:0:164:19::"""2"" is not a valid mode for open.":UNDEFINED
unspecified-encoding:164:0:164:19::Using open without explicitly specifying an encoding:UNDEFINED

0 comments on commit f1d930b

Please sign in to comment.