File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -671,7 +671,7 @@ def ignore(self, node):
671
671
672
672
# "stmt" type nodes
673
673
DELETE = PRINT = FOR = ASYNCFOR = WHILE = IF = WITH = WITHITEM = \
674
- ASYNCWITH = ASYNCWITHITEM = RAISE = TRYFINALLY = ASSERT = EXEC = \
674
+ ASYNCWITH = ASYNCWITHITEM = RAISE = TRYFINALLY = EXEC = \
675
675
EXPR = ASSIGN = handleChildren
676
676
677
677
PASS = ignore
@@ -697,6 +697,11 @@ def ignore(self, node):
697
697
# additional node types
698
698
COMPREHENSION = KEYWORD = FORMATTEDVALUE = handleChildren
699
699
700
+ def ASSERT (self , node ):
701
+ if isinstance (node .test , ast .Tuple ) and node .test .elts != []:
702
+ self .report (messages .AssertTuple , node )
703
+ self .handleChildren (node )
704
+
700
705
def GLOBAL (self , node ):
701
706
"""
702
707
Keep track of globals declarations.
Original file line number Diff line number Diff line change @@ -191,3 +191,10 @@ class TooManyExpressionsInStarredAssignment(Message):
191
191
Too many expressions in an assignment with star-unpacking
192
192
"""
193
193
message = 'too many expressions in star-unpacking assignment'
194
+
195
+
196
+ class AssertTuple (Message ):
197
+ """
198
+ Assertion test is a tuple, which are always True.
199
+ """
200
+ message = 'assertion is always true, perhaps remove parentheses?'
Original file line number Diff line number Diff line change @@ -1633,6 +1633,40 @@ def test_augmentedAssignmentImportedFunctionCall(self):
1633
1633
baz += bar()
1634
1634
''' )
1635
1635
1636
+ def test_assert_without_message (self ):
1637
+ """An assert without a message is not an error."""
1638
+ self .flakes ('''
1639
+ a = 1
1640
+ assert a
1641
+ ''' )
1642
+
1643
+ def test_assert_with_message (self ):
1644
+ """An assert with a message is not an error."""
1645
+ self .flakes ('''
1646
+ a = 1
1647
+ assert a, 'x'
1648
+ ''' )
1649
+
1650
+ def test_assert_tuple (self ):
1651
+ """An assert of a non-empty tuple is always True."""
1652
+ self .flakes ('''
1653
+ assert (False, 'x')
1654
+ assert (False, )
1655
+ ''' , m .AssertTuple , m .AssertTuple )
1656
+
1657
+ def test_assert_tuple_empty (self ):
1658
+ """An assert of an empty tuple is always False."""
1659
+ self .flakes ('''
1660
+ assert ()
1661
+ ''' )
1662
+
1663
+ def test_assert_static (self ):
1664
+ """An assert of a static value is not an error."""
1665
+ self .flakes ('''
1666
+ assert True
1667
+ assert 1
1668
+ ''' )
1669
+
1636
1670
@skipIf (version_info < (3 , 3 ), 'new in Python 3.3' )
1637
1671
def test_yieldFromUndefined (self ):
1638
1672
"""
You can’t perform that action at this time.
0 commit comments