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 a crash from astroid.InferenceError raised on copy.copy #4892

Merged
merged 1 commit into from
Aug 21, 2021
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
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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'])