diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-08-21 19:00:50 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-08-21 19:14:34 +0200 |
commit | d9dc89cfe78881f9ad210a17d0d4292d1d94037b (patch) | |
tree | 729dab04989b3cff4ef53c111446856f644449b3 | |
parent | 5150d89c0dbd12f9cf8b9a4fe60e7c265c55531d (diff) | |
download | pylint-git-d9dc89cfe78881f9ad210a17d0d4292d1d94037b.tar.gz |
Fix a crash from astroid.InferenceError raised on copy.copy
Closes #4891
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | pylint/checkers/stdlib.py | 10 | ||||
-rw-r--r-- | tests/functional/r/regression/regression_4891.py | 16 |
3 files changed, 29 insertions, 3 deletions
@@ -22,6 +22,12 @@ Release date: TBA Closes #4886 +* Fix a crash in the checker raising ``shallow-copy-environ`` when failing to infer + on ``copy.copy`` + + Closes #4896 + + What's New in Pylint 2.10.1? ============================ diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py index cffc8a4d5..b7a6e031b 100644 --- a/pylint/checkers/stdlib.py +++ b/pylint/checkers/stdlib.py @@ -483,9 +483,13 @@ class StdlibChecker(DeprecatedMixin, BaseChecker): if "check" not in kwargs: self.add_message("subprocess-run-check", node=node) - def _check_shallow_copy_environ(self, node): + def _check_shallow_copy_environ(self, node: nodes.Call) -> None: arg = utils.get_argument_from_call(node, position=0) - for inferred in arg.inferred(): + try: + inferred_args = arg.inferred() + except astroid.InferenceError: + return + for inferred in inferred_args: if inferred.qname() == OS_ENVIRON: self.add_message("shallow-copy-environ", node=node) break @@ -505,7 +509,7 @@ class StdlibChecker(DeprecatedMixin, BaseChecker): "unspecified-encoding", "forgotten-debug-statement", ) - def visit_call(self, node): + def visit_call(self, node: nodes.Call) -> None: """Visit a Call node.""" self.check_deprecated_class_in_call(node) for inferred in utils.infer_all(node.func): diff --git a/tests/functional/r/regression/regression_4891.py b/tests/functional/r/regression/regression_4891.py new file mode 100644 index 000000000..34945e812 --- /dev/null +++ b/tests/functional/r/regression/regression_4891.py @@ -0,0 +1,16 @@ +# pylint: disable=missing-module-docstring +# pylint: disable=too-few-public-methods +import copy + +class MyData: + ''' + class docstring + ''' + def __init__(self): + self.data = {} + + def process(self): + ''' + another method is responsible for putting "static_key" + ''' + copy.copy(self.data['static_key']) |