src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Simplify/translations.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9277
471c5a263d53
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
13 13
14 _simplifyMessages = { 14 _simplifyMessages = {
15 # Python-specifics 15 # Python-specifics
16 "Y101": QCoreApplication.translate( 16 "Y101": QCoreApplication.translate(
17 "SimplifyChecker", 17 "SimplifyChecker",
18 '''Multiple "isinstance()" calls which can be merged into a single ''' 18 """Multiple "isinstance()" calls which can be merged into a single """
19 '''call for variable "{0}"'''), 19 '''call for variable "{0}"''',
20 ),
20 "Y102": QCoreApplication.translate( 21 "Y102": QCoreApplication.translate(
21 "SimplifyChecker", 22 "SimplifyChecker",
22 '''Use a single if-statement instead of nested if-statements'''), 23 """Use a single if-statement instead of nested if-statements""",
24 ),
23 "Y103": QCoreApplication.translate( 25 "Y103": QCoreApplication.translate(
24 "SimplifyChecker", 26 "SimplifyChecker", """Return the condition "{0}" directly"""
25 '''Return the condition "{0}" directly'''), 27 ),
26 "Y104": QCoreApplication.translate( 28 "Y104": QCoreApplication.translate("SimplifyChecker", '''Use "yield from {0}"'''),
27 "SimplifyChecker",
28 '''Use "yield from {0}"'''),
29 "Y105": QCoreApplication.translate( 29 "Y105": QCoreApplication.translate(
30 "SimplifyChecker", 30 "SimplifyChecker", '''Use "with contextlib.suppress({0}):"'''
31 '''Use "with contextlib.suppress({0}):"'''), 31 ),
32 "Y106": QCoreApplication.translate( 32 "Y106": QCoreApplication.translate(
33 "SimplifyChecker", 33 "SimplifyChecker", """Handle error-cases first"""
34 '''Handle error-cases first'''), 34 ),
35 "Y107": QCoreApplication.translate( 35 "Y107": QCoreApplication.translate(
36 "SimplifyChecker", 36 "SimplifyChecker", """Don't use return in try/except and finally"""
37 '''Don't use return in try/except and finally'''), 37 ),
38 "Y108": QCoreApplication.translate( 38 "Y108": QCoreApplication.translate(
39 "SimplifyChecker", 39 "SimplifyChecker",
40 '''Use ternary operator "{0} = {1} if {2} else {3}" ''' 40 """Use ternary operator "{0} = {1} if {2} else {3}" """
41 '''instead of if-else-block'''), 41 """instead of if-else-block""",
42 ),
42 "Y109": QCoreApplication.translate( 43 "Y109": QCoreApplication.translate(
43 "SimplifyChecker", 44 "SimplifyChecker", '''Use "{0} in {1}" instead of "{2}"'''
44 '''Use "{0} in {1}" instead of "{2}"'''), 45 ),
45 "Y110": QCoreApplication.translate( 46 "Y110": QCoreApplication.translate(
46 "SimplifyChecker", 47 "SimplifyChecker", '''Use "any({0} for {1} in {2})"'''
47 '''Use "any({0} for {1} in {2})"'''), 48 ),
48 "Y111": QCoreApplication.translate( 49 "Y111": QCoreApplication.translate(
49 "SimplifyChecker", 50 "SimplifyChecker", '''Use "all({0} for {1} in {2})"'''
50 '''Use "all({0} for {1} in {2})"'''), 51 ),
51 "Y112": QCoreApplication.translate( 52 "Y112": QCoreApplication.translate(
52 "SimplifyChecker", 53 "SimplifyChecker", '''Use "{0}" instead of "{1}"'''
53 '''Use "{0}" instead of "{1}"'''), 54 ),
54 "Y113": QCoreApplication.translate( 55 "Y113": QCoreApplication.translate(
55 "SimplifyChecker", 56 "SimplifyChecker", '''Use enumerate instead of "{0}"'''
56 '''Use enumerate instead of "{0}"'''), 57 ),
57 "Y114": QCoreApplication.translate( 58 "Y114": QCoreApplication.translate(
58 "SimplifyChecker", 59 "SimplifyChecker", """Use logical or ("({0}) or ({1})") and a single body"""
59 '''Use logical or ("({0}) or ({1})") and a single body'''), 60 ),
60 "Y115": QCoreApplication.translate( 61 "Y115": QCoreApplication.translate(
61 "SimplifyChecker", 62 "SimplifyChecker", """Use context handler for opening files"""
62 '''Use context handler for opening files'''), 63 ),
63 "Y116": QCoreApplication.translate( 64 "Y116": QCoreApplication.translate(
64 "SimplifyChecker", 65 "SimplifyChecker",
65 '''Use a dictionary lookup instead of 3+ if/elif-statements: ''' 66 """Use a dictionary lookup instead of 3+ if/elif-statements: """
66 '''return {0}'''), 67 """return {0}""",
68 ),
67 "Y117": QCoreApplication.translate( 69 "Y117": QCoreApplication.translate(
68 "SimplifyChecker", 70 "SimplifyChecker", """Use "{0}" instead of multiple with statements"""
69 '''Use "{0}" instead of multiple with statements'''), 71 ),
70 "Y118": QCoreApplication.translate( 72 "Y118": QCoreApplication.translate(
71 "SimplifyChecker", 73 "SimplifyChecker", '''Use "{0} in {1}" instead of "{0} in {1}.keys()"'''
72 '''Use "{0} in {1}" instead of "{0} in {1}.keys()"'''), 74 ),
73 "Y119": QCoreApplication.translate( 75 "Y119": QCoreApplication.translate(
74 "SimplifyChecker", 76 "SimplifyChecker", '''Use a dataclass for "class {0}"'''
75 '''Use a dataclass for "class {0}"'''), 77 ),
76 "Y120": QCoreApplication.translate( 78 "Y120": QCoreApplication.translate(
77 "SimplifyChecker", 79 "SimplifyChecker", '''Use "class {0}:" instead of "class {0}(object):"'''
78 '''Use "class {0}:" instead of "class {0}(object):"'''), 80 ),
79 "Y121": QCoreApplication.translate( 81 "Y121": QCoreApplication.translate(
80 "SimplifyChecker", 82 "SimplifyChecker",
81 '''Use "class {0}({1}):" instead of "class {0}({1}, object):"'''), 83 '''Use "class {0}({1}):" instead of "class {0}({1}, object):"''',
84 ),
82 "Y122": QCoreApplication.translate( 85 "Y122": QCoreApplication.translate(
83 "SimplifyChecker", 86 "SimplifyChecker", '''Use "{0}.get({1})" instead of "if {1} in {0}: {0}[{1}]"'''
84 '''Use "{0}.get({1})" instead of "if {1} in {0}: {0}[{1}]"'''), 87 ),
85
86 # Python-specifics not part of flake8-simplify 88 # Python-specifics not part of flake8-simplify
87 "Y181": QCoreApplication.translate( 89 "Y181": QCoreApplication.translate(
88 "SimplifyChecker", 90 "SimplifyChecker", '''Use "{0}" instead of "{1}"'''
89 '''Use "{0}" instead of "{1}"'''), 91 ),
90 "Y182": QCoreApplication.translate( 92 "Y182": QCoreApplication.translate(
91 "SimplifyChecker", 93 "SimplifyChecker", '''Use "super()" instead of "{0}"'''
92 '''Use "super()" instead of "{0}"'''), 94 ),
93
94 # Comparations 95 # Comparations
95 "Y201": QCoreApplication.translate( 96 "Y201": QCoreApplication.translate(
96 "SimplifyChecker", 97 "SimplifyChecker", '''Use "{0} != {1}" instead of "not {0} == {1}"'''
97 '''Use "{0} != {1}" instead of "not {0} == {1}"'''), 98 ),
98 "Y202": QCoreApplication.translate( 99 "Y202": QCoreApplication.translate(
99 "SimplifyChecker", 100 "SimplifyChecker", '''Use "{0} == {1}" instead of "not {0} != {1}"'''
100 '''Use "{0} == {1}" instead of "not {0} != {1}"'''), 101 ),
101 "Y203": QCoreApplication.translate( 102 "Y203": QCoreApplication.translate(
102 "SimplifyChecker", 103 "SimplifyChecker", '''Use "{0} not in {1}" instead of "not {0} in {1}"'''
103 '''Use "{0} not in {1}" instead of "not {0} in {1}"'''), 104 ),
104 "Y204": QCoreApplication.translate( 105 "Y204": QCoreApplication.translate(
105 "SimplifyChecker", 106 "SimplifyChecker", '''Use "{0} >= {1}" instead of "not ({0} < {1})"'''
106 '''Use "{0} >= {1}" instead of "not ({0} < {1})"'''), 107 ),
107 "Y205": QCoreApplication.translate( 108 "Y205": QCoreApplication.translate(
108 "SimplifyChecker", 109 "SimplifyChecker", '''Use "{0} > {1}" instead of "not ({0} <= {1})"'''
109 '''Use "{0} > {1}" instead of "not ({0} <= {1})"'''), 110 ),
110 "Y206": QCoreApplication.translate( 111 "Y206": QCoreApplication.translate(
111 "SimplifyChecker", 112 "SimplifyChecker", '''Use "{0} <= {1}" instead of "not ({0} > {1})"'''
112 '''Use "{0} <= {1}" instead of "not ({0} > {1})"'''), 113 ),
113 "Y207": QCoreApplication.translate( 114 "Y207": QCoreApplication.translate(
114 "SimplifyChecker", 115 "SimplifyChecker", '''Use "{0} < {1}" instead of "not ({0} >= {1})"'''
115 '''Use "{0} < {1}" instead of "not ({0} >= {1})"'''), 116 ),
116 "Y208": QCoreApplication.translate( 117 "Y208": QCoreApplication.translate(
117 "SimplifyChecker", 118 "SimplifyChecker", '''Use "{0}" instead of "not (not {0})"'''
118 '''Use "{0}" instead of "not (not {0})"'''), 119 ),
119
120 "Y211": QCoreApplication.translate( 120 "Y211": QCoreApplication.translate(
121 "SimplifyChecker", 121 "SimplifyChecker", '''Use "{1}" instead of "True if {0} else False"'''
122 '''Use "{1}" instead of "True if {0} else False"'''), 122 ),
123 "Y212": QCoreApplication.translate( 123 "Y212": QCoreApplication.translate(
124 "SimplifyChecker", 124 "SimplifyChecker", '''Use "{1}" instead of "False if {0} else True"'''
125 '''Use "{1}" instead of "False if {0} else True"'''), 125 ),
126 "Y213": QCoreApplication.translate( 126 "Y213": QCoreApplication.translate(
127 "SimplifyChecker", 127 "SimplifyChecker",
128 '''Use "{0} if {0} else {1}" instead of "{1} if not {0} else {0}"'''), 128 '''Use "{0} if {0} else {1}" instead of "{1} if not {0} else {0}"''',
129 129 ),
130 "Y221": QCoreApplication.translate( 130 "Y221": QCoreApplication.translate(
131 "SimplifyChecker", 131 "SimplifyChecker", '''Use "False" instead of "{0} and not {0}"'''
132 '''Use "False" instead of "{0} and not {0}"'''), 132 ),
133 "Y222": QCoreApplication.translate( 133 "Y222": QCoreApplication.translate(
134 "SimplifyChecker", 134 "SimplifyChecker", '''Use "True" instead of "{0} or not {0}"'''
135 '''Use "True" instead of "{0} or not {0}"'''), 135 ),
136 "Y223": QCoreApplication.translate( 136 "Y223": QCoreApplication.translate(
137 "SimplifyChecker", 137 "SimplifyChecker", '''Use "True" instead of "... or True"'''
138 '''Use "True" instead of "... or True"'''), 138 ),
139 "Y224": QCoreApplication.translate( 139 "Y224": QCoreApplication.translate(
140 "SimplifyChecker", 140 "SimplifyChecker", '''Use "False" instead of "... and False"'''
141 '''Use "False" instead of "... and False"'''), 141 ),
142
143 # Opinionated 142 # Opinionated
144 "Y301": QCoreApplication.translate( 143 "Y301": QCoreApplication.translate(
145 "SimplifyChecker", 144 "SimplifyChecker",
146 '''Use "{1} == {0}" instead of "{0} == {1}" (Yoda-condition)'''), 145 """Use "{1} == {0}" instead of "{0} == {1}" (Yoda-condition)""",
147 146 ),
148 # General Code Style 147 # General Code Style
149 "Y401": QCoreApplication.translate( 148 "Y401": QCoreApplication.translate(
150 "SimplifyChecker", 149 "SimplifyChecker", """Use keyword-argument instead of magic boolean"""
151 '''Use keyword-argument instead of magic boolean'''), 150 ),
152 "Y402": QCoreApplication.translate( 151 "Y402": QCoreApplication.translate(
153 "SimplifyChecker", 152 "SimplifyChecker", """Use keyword-argument instead of magic number"""
154 '''Use keyword-argument instead of magic number'''), 153 ),
155 } 154 }
156 155
157 _simplifyMessagesSampleArgs = { 156 _simplifyMessagesSampleArgs = {
158 # Python-specifics 157 # Python-specifics
159 "Y101": ["foo"], 158 "Y101": ["foo"],
172 "Y118": ["foo", "bar_dict"], 171 "Y118": ["foo", "bar_dict"],
173 "Y119": ["Foo"], 172 "Y119": ["Foo"],
174 "Y120": ["Foo"], 173 "Y120": ["Foo"],
175 "Y121": ["FooBar", "Foo"], 174 "Y121": ["FooBar", "Foo"],
176 "Y122": ["bar_dict", "'foo'"], 175 "Y122": ["bar_dict", "'foo'"],
177
178 # Python-specifics not part of flake8-simplify 176 # Python-specifics not part of flake8-simplify
179 "Y181": ["foo += 42", "foo = foo + 42"], 177 "Y181": ["foo += 42", "foo = foo + 42"],
180 "Y182": ["super()"], 178 "Y182": ["super()"],
181
182 # Comparations 179 # Comparations
183 "Y201": ["foo", "bar"], 180 "Y201": ["foo", "bar"],
184 "Y202": ["foo", "bar"], 181 "Y202": ["foo", "bar"],
185 "Y203": ["foo", "bar"], 182 "Y203": ["foo", "bar"],
186 "Y204": ["foo", "bar"], 183 "Y204": ["foo", "bar"],
187 "Y205": ["foo", "bar"], 184 "Y205": ["foo", "bar"],
188 "Y206": ["foo", "bar"], 185 "Y206": ["foo", "bar"],
189 "Y207": ["foo", "bar"], 186 "Y207": ["foo", "bar"],
190 "Y208": ["foo"], 187 "Y208": ["foo"],
191
192 "Y211": ["foo", "bool(foo)"], 188 "Y211": ["foo", "bool(foo)"],
193 "Y212": ["foo", "not foo"], 189 "Y212": ["foo", "not foo"],
194 "Y213": ["foo", "bar"], 190 "Y213": ["foo", "bar"],
195
196 "Y221": ["foo"], 191 "Y221": ["foo"],
197 "Y222": ["foo"], 192 "Y222": ["foo"],
198
199 # Opinionated 193 # Opinionated
200 "Y301": ["42", "foo"], 194 "Y301": ["42", "foo"],
201
202 # General Code Style 195 # General Code Style
203 } 196 }

eric ide

mercurial