Skip to content

Commit

Permalink
Fix a crash from astroid.InferenceError raised on copy.copy
Browse files Browse the repository at this point in the history
Closes #4891
  • Loading branch information
Pierre-Sassoulas committed Aug 21, 2021
1 parent 5150d89 commit d9dc89c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Expand Up @@ -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?
============================
Expand Down
10 changes: 7 additions & 3 deletions pylint/checkers/stdlib.py
Expand Up @@ -483,9 +483,13 @@ def _check_for_check_kw_in_run(self, node):
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
Expand All @@ -505,7 +509,7 @@ def _check_shallow_copy_environ(self, node):
"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):
Expand Down
16 changes: 16 additions & 0 deletions 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'])

0 comments on commit d9dc89c

Please sign in to comment.