Skip to content

Commit 6fac84e

Browse files
jacobtylerwallsPierre-Sassoulas
authored andcommitted
Fix a crash in the optional private_import extension
1 parent 3ac7d11 commit 6fac84e

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/whatsnew/2/2.14/full.rst

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

2323
Closes #6810
2424

25+
* Fix a crash in the optional ``pylint.extensions.private_import`` extension.
26+
27+
Closes #6624
28+
2529

2630
What's New in Pylint 2.14.0?
2731
----------------------------

pylint/extensions/private_import.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ def _assignments_call_private_name(
234234
while isinstance(current_attribute, (nodes.Attribute, nodes.Call)):
235235
if isinstance(current_attribute, nodes.Call):
236236
current_attribute = current_attribute.func
237-
current_attribute = current_attribute.expr
237+
if not isinstance(current_attribute, nodes.Name):
238+
current_attribute = current_attribute.expr
238239
if (
239240
isinstance(current_attribute, nodes.Name)
240241
and current_attribute.name == private_name

tests/functional/ext/private_import/private_import.py

+13
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,16 @@ def c2_func() -> _TypeContainerC.C:
119119
import _private_module_unreachable # [import-private-name]
120120
my_var8: _private_module_unreachable.Thing8
121121
_private_module_unreachable.Thing8()
122+
123+
124+
# pylint: disable=too-few-public-methods
125+
class Regression6624:
126+
"""Ensure that an import statement precedes this case."""
127+
def get_example(self):
128+
example: Example = Example().save()
129+
return example
130+
131+
132+
class Example:
133+
def save(self):
134+
return self

0 commit comments

Comments
 (0)