Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when open is called with an integer mode #6415

Merged
merged 1 commit into from Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions ChangeLog
Expand Up @@ -225,6 +225,16 @@ Release date: TBA
(Ie. not necessarily at the end)


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?
============================
Release date: 2022-04-20
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 @@ -659,7 +659,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