diff --git a/ChangeLog b/ChangeLog index 9054bd22f4..ee6e4b3f95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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? diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst index 00d134a8c7..bd002d0216 100644 --- a/doc/whatsnew/2.13.rst +++ b/doc/whatsnew/2.13.rst @@ -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 diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py index 6eeaa20a90..daf9324445 100644 --- a/pylint/checkers/stdlib.py +++ b/pylint/checkers/stdlib.py @@ -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: diff --git a/tests/functional/u/unspecified_encoding_py38.py b/tests/functional/u/unspecified_encoding_py38.py index 20233f0734..66b8523f4c 100644 --- a/tests/functional/u/unspecified_encoding_py38.py +++ b/tests/functional/u/unspecified_encoding_py38.py @@ -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] diff --git a/tests/functional/u/unspecified_encoding_py38.txt b/tests/functional/u/unspecified_encoding_py38.txt index b3371299f5..8cf19dee45 100644 --- a/tests/functional/u/unspecified_encoding_py38.txt +++ b/tests/functional/u/unspecified_encoding_py38.txt @@ -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