summaryrefslogtreecommitdiff
path: root/tests/functional
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2022-03-25 03:24:17 -0400
committerGitHub <noreply@github.com>2022-03-25 08:24:17 +0100
commit129c7302ceaabbbbf41a9872661a3550069b37e3 (patch)
tree03295ead8f6fbb12dbff7d42879840936d7ad49d /tests/functional
parentfe57cc721defc1f81aaed875d1b85ac6d1761909 (diff)
downloadpylint-git-129c7302ceaabbbbf41a9872661a3550069b37e3.tar.gz
Fix #1555: Fix false negative for `no-member` when assigning instance attribute to itself (#5544)
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/n/no/no_member_assign_same_line.py37
-rw-r--r--tests/functional/n/no/no_member_assign_same_line.txt1
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/functional/n/no/no_member_assign_same_line.py b/tests/functional/n/no/no_member_assign_same_line.py
new file mode 100644
index 000000000..45138d933
--- /dev/null
+++ b/tests/functional/n/no/no_member_assign_same_line.py
@@ -0,0 +1,37 @@
+"""Tests for no-member for self-referencing instance attributes
+See https://github.com/PyCQA/pylint/issues/1555
+"""
+# pylint: disable=too-few-public-methods
+
+
+class ClassWithMember:
+ """Member defined in superclass."""
+ def __init__(self):
+ self.member = True
+
+
+class AssignMemberInSameLine:
+ """This class attempts to assign and access a member in the same line."""
+ def __init__(self):
+ self.member = self.member # [no-member]
+
+
+class AssignMemberInSameLineAfterTypeAnnotation:
+ """This might emit a message like `maybe-no-member` in the future."""
+ def __init__(self):
+ self.member: bool
+ self.member = self.member
+
+
+class AssignMemberFromSuper1(ClassWithMember):
+ """This assignment is valid due to inheritance."""
+ def __init__(self):
+ self.member = self.member
+ super().__init__()
+
+
+class AssignMemberFromSuper2(ClassWithMember):
+ """This assignment is valid due to inheritance."""
+ def __init__(self):
+ super().__init__()
+ self.member = self.member
diff --git a/tests/functional/n/no/no_member_assign_same_line.txt b/tests/functional/n/no/no_member_assign_same_line.txt
new file mode 100644
index 000000000..a6b15b9cd
--- /dev/null
+++ b/tests/functional/n/no/no_member_assign_same_line.txt
@@ -0,0 +1 @@
+no-member:16:22:16:33:AssignMemberInSameLine.__init__:Instance of 'AssignMemberInSameLine' has no 'member' member:INFERENCE