Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-lint
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-lint
Commits
2c32ba89
Commit
2c32ba89
authored
Aug 20, 2016
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop false warnings on chained comparisons. Fixes #43
parent
f3b05740
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
edx_lint/pylint/right_assert_check.py
+8
-3
test/input/func_asserts_check.py
+10
-0
No files found.
edx_lint/pylint/right_assert_check.py
View file @
2c32ba89
...
...
@@ -18,8 +18,8 @@ def register_checkers(linter):
class
AssertChecker
(
BaseChecker
):
"""
Implements a few pylint checks on unitests asserts - making sure the right
assert is used if assertTrue or
assertFalse are misused.
Implements a few pylint checks on unitests asserts - making sure the right
assert
is used if assertTrue or assert
False are misused.
"""
__implements__
=
(
IAstroidChecker
,)
...
...
@@ -77,7 +77,8 @@ class AssertChecker(BaseChecker):
Check that various assertTrue/False functions are not misused.
"""
if
not
isinstance
(
node
.
func
,
astroid
.
Getattr
):
# If it isn't a getattr ignore this. All the assertMethods are attrs of self:
# If it isn't a getattr ignore this. All the assertMethods are
# attributes of self:
return
if
node
.
func
.
attrname
not
in
self
.
AFFECTED_ASSERTS
:
...
...
@@ -88,6 +89,10 @@ class AssertChecker(BaseChecker):
existing_code
=
"
%
s(
%
s)"
%
(
node
.
func
.
attrname
,
first_arg
.
as_string
())
if
isinstance
(
first_arg
,
astroid
.
Compare
):
if
len
(
first_arg
.
ops
)
>
1
:
# This is a chained comparison, which we can't do anything with.
return
compare
=
first_arg
.
ops
[
0
][
0
]
right
=
first_arg
.
ops
[
0
][
1
]
if
isinstance
(
right
,
astroid
.
Const
)
and
right
.
value
is
None
:
...
...
test/input/func_asserts_check.py
View file @
2c32ba89
...
...
@@ -56,3 +56,13 @@ class TestStringMethods(unittest.TestCase):
This uses the wrong assert, but has a pragma to quiet the message.
"""
self
.
assertTrue
(
"a"
in
"lala"
)
# pylint: disable=wrong-assert-type
def
test_chained_comparisons
(
self
):
"""
These uses of assertTrue and assertFalse are fine, because we can't
pick apart the chained comparisons.
"""
my_value
=
my_other_value
=
10
self
.
assertTrue
(
0
<
my_value
<
1000
)
self
.
assertFalse
(
0
<
my_value
<
5
)
self
.
assertTrue
(
my_value
==
my_other_value
==
10
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment