Skip to content

Commit d9dc89c

Browse files
Fix a crash from astroid.InferenceError raised on copy.copy
Closes #4891
1 parent 5150d89 commit d9dc89c

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Release date: TBA
2222

2323
Closes #4886
2424

25+
* Fix a crash in the checker raising ``shallow-copy-environ`` when failing to infer
26+
on ``copy.copy``
27+
28+
Closes #4896
29+
30+
2531

2632
What's New in Pylint 2.10.1?
2733
============================

pylint/checkers/stdlib.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,13 @@ def _check_for_check_kw_in_run(self, node):
483483
if "check" not in kwargs:
484484
self.add_message("subprocess-run-check", node=node)
485485

486-
def _check_shallow_copy_environ(self, node):
486+
def _check_shallow_copy_environ(self, node: nodes.Call) -> None:
487487
arg = utils.get_argument_from_call(node, position=0)
488-
for inferred in arg.inferred():
488+
try:
489+
inferred_args = arg.inferred()
490+
except astroid.InferenceError:
491+
return
492+
for inferred in inferred_args:
489493
if inferred.qname() == OS_ENVIRON:
490494
self.add_message("shallow-copy-environ", node=node)
491495
break
@@ -505,7 +509,7 @@ def _check_shallow_copy_environ(self, node):
505509
"unspecified-encoding",
506510
"forgotten-debug-statement",
507511
)
508-
def visit_call(self, node):
512+
def visit_call(self, node: nodes.Call) -> None:
509513
"""Visit a Call node."""
510514
self.check_deprecated_class_in_call(node)
511515
for inferred in utils.infer_all(node.func):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# pylint: disable=missing-module-docstring
2+
# pylint: disable=too-few-public-methods
3+
import copy
4+
5+
class MyData:
6+
'''
7+
class docstring
8+
'''
9+
def __init__(self):
10+
self.data = {}
11+
12+
def process(self):
13+
'''
14+
another method is responsible for putting "static_key"
15+
'''
16+
copy.copy(self.data['static_key'])

0 commit comments

Comments
 (0)