Commit 55fed7c 1 parent 433f73b commit 55fed7c Copy full SHA for 55fed7c
File tree 3 files changed +8
-6
lines changed
pylint/checkers/refactoring
3 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,11 @@ def visit_call(self, node):
107
107
108
108
@staticmethod
109
109
def instance_has_bool (class_def : astroid .ClassDef ) -> bool :
110
- return any (hasattr (f , "name" ) and f .name == "__bool__" for f in class_def .body )
110
+ try :
111
+ class_def .getattr ("__bool__" )
112
+ except astroid .AttributeInferenceError :
113
+ ...
114
+ return False
111
115
112
116
@utils .check_messages ("len-as-condition" )
113
117
def visit_unaryop (self , node ):
Original file line number Diff line number Diff line change @@ -120,9 +120,7 @@ class ChildClassWithoutBool(ClassWithoutBool):
120
120
pass
121
121
122
122
assert len (ClassWithBool ())
123
- # We could expect to not have a len-as-condition for ChildClassWithBool,
124
- # but I don't think the required analysis is worth it.
125
- assert len (ChildClassWithBool ()) # [len-as-condition]
123
+ assert len (ChildClassWithBool ())
126
124
assert len (ClassWithoutBool ()) # [len-as-condition]
127
125
assert len (ChildClassWithoutBool ()) # [len-as-condition]
128
126
assert len (range (0 )) # [len-as-condition]
Original file line number Diff line number Diff line change @@ -13,12 +13,12 @@ len-as-condition:98:github_issue_1331_v3:Do not use `len(SEQUENCE)` without comp
13
13
len-as-condition:101:github_issue_1331_v4:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
14
14
len-as-condition:103::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
15
15
len-as-condition:104::Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
16
+ len-as-condition:124:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
16
17
len-as-condition:125:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
17
18
len-as-condition:126:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
18
19
len-as-condition:127:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
19
20
len-as-condition:128:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
20
21
len-as-condition:129:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
21
22
len-as-condition:130:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
22
23
len-as-condition:131:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
23
- len-as-condition:132:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
24
- len-as-condition:163:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
24
+ len-as-condition:161:github_issue_1879:Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty
You can’t perform that action at this time.
0 commit comments