@@ -13,6 +13,97 @@ class Test(TestCase):
1313 def test_duplicateArgs (self ):
1414 self .flakes ('def fu(bar, bar): pass' , m .DuplicateArgument )
1515
16+ def test_duplicate_keys (self ):
17+ self .flakes ("{'yes': 1, 'yes': 1}" , m .DuplicateDictionaryKey )
18+
19+ def test_multiple_duplicate_keys (self ):
20+ self .flakes (
21+ "{'yes': 1, 'yes': 1, 'no': 2, 'no': 3}" ,
22+ m .DuplicateDictionaryKey , m .DuplicateDictionaryKey )
23+
24+ def test_duplicate_keys_in_function (self ):
25+ self .flakes ('''
26+ def f(thing):
27+ pass
28+ f({'yes': 1, 'yes': 4})
29+ ''' , m .DuplicateDictionaryKey )
30+
31+ def test_duplicate_keys_in_lambda (self ):
32+ self .flakes ("lambda x: {(0,1): 1, (0,1): 1}" ,
33+ m .DuplicateDictionaryKey )
34+
35+ def test_duplicate_keys_tuples (self ):
36+ self .flakes ("{(0,1): 1, (0,1): 1}" , m .DuplicateDictionaryKey )
37+
38+ def test_duplicate_keys_ints (self ):
39+ self .flakes ("{1: 1, 1: 1}" , m .DuplicateDictionaryKey )
40+
41+ def test_duplicate_keys_bools (self ):
42+ if version_info < (3 , 4 ):
43+ expected = m .DuplicateVariableDictionaryKey
44+ else :
45+ expected = m .DuplicateDictionaryKey
46+ self .flakes ("{True: 1, True: 1}" , expected )
47+
48+ def test_duplicate_keys_none (self ):
49+ if version_info < (3 , 4 ):
50+ expected = m .DuplicateVariableDictionaryKey
51+ else :
52+ expected = m .DuplicateDictionaryKey
53+ self .flakes ("{None: 1, None: 1}" , expected )
54+
55+ def test_duplicate_variable_keys (self ):
56+ self .flakes ('''
57+ a = 1
58+ {a: 2, a: 3}
59+ ''' , m .DuplicateVariableDictionaryKey )
60+
61+ def test_duplicate_key_float_and_int (self ):
62+ self .flakes ('''
63+ {1: 1, 1.0: 1}
64+ ''' , m .DuplicateDictionaryKey )
65+
66+ def test_no_duplicate_key_errors (self ):
67+ self .flakes ('''
68+ {'yes': 1, 'no': 1}
69+ ''' )
70+
71+ def test_no_duplicate_key_errors_func_call (self ):
72+ self .flakes ('''
73+ def test(thing):
74+ pass
75+ test({True: 1, None: 2, False: 1})
76+ ''' )
77+
78+ def test_no_duplicate_key_errors_bool_or_none (self ):
79+ self .flakes ("{True: 1, None: 2, False: 1}" )
80+
81+ def test_no_duplicate_key_errors_ints (self ):
82+ self .flakes ('''
83+ {1: 1, 2: 1}
84+ ''' )
85+
86+ def test_no_duplicate_key_errors_vars (self ):
87+ self .flakes ('''
88+ test = 'yes'
89+ rest = 'yes'
90+ {test: 1, rest: 2}
91+ ''' )
92+
93+ def test_no_duplicate_key_errors_tuples (self ):
94+ self .flakes ('''
95+ {(0,1): 1, (0,2): 1}
96+ ''' )
97+
98+ def test_no_duplicate_key_errors_instance_attributes (self ):
99+ self .flakes ('''
100+ class Test():
101+ pass
102+ f = Test()
103+ f.a = 1
104+ {f.a: 1, f.a: 1}
105+ ''' )
106+
16107 def test_localReferencedBeforeAssignment (self ):
17108 self .flakes ('''
18109 a = 1
0 commit comments