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

branch
eric7
changeset 11147
dee6e106b4d3
parent 11145
d328a7b74fd8
equal deleted inserted replaced
11146:59e04f7003e9 11147:dee6e106b4d3
11 11
12 from PyQt6.QtCore import QCoreApplication 12 from PyQt6.QtCore import QCoreApplication
13 13
14 _simplifyMessages = { 14 _simplifyMessages = {
15 # Python-specifics 15 # Python-specifics
16 "Y101": QCoreApplication.translate( 16 "Y-101": 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 ),
21 "Y102": QCoreApplication.translate( 21 "Y-102": QCoreApplication.translate(
22 "SimplifyChecker", 22 "SimplifyChecker",
23 """Use a single if-statement instead of nested if-statements""", 23 """Use a single if-statement instead of nested if-statements""",
24 ), 24 ),
25 "Y103": QCoreApplication.translate( 25 "Y-103": QCoreApplication.translate(
26 "SimplifyChecker", """Return the condition "{0}" directly""" 26 "SimplifyChecker", """Return the condition "{0}" directly"""
27 ), 27 ),
28 "Y104": QCoreApplication.translate("SimplifyChecker", '''Use "yield from {0}"'''), 28 "Y-104": QCoreApplication.translate("SimplifyChecker", '''Use "yield from {0}"'''),
29 "Y105": QCoreApplication.translate( 29 "Y-105": QCoreApplication.translate(
30 "SimplifyChecker", '''Use "with contextlib.suppress({0}):"''' 30 "SimplifyChecker", '''Use "with contextlib.suppress({0}):"'''
31 ), 31 ),
32 "Y106": QCoreApplication.translate( 32 "Y-106": QCoreApplication.translate(
33 "SimplifyChecker", """Handle error-cases first""" 33 "SimplifyChecker", """Handle error-cases first"""
34 ), 34 ),
35 "Y107": QCoreApplication.translate( 35 "Y-107": QCoreApplication.translate(
36 "SimplifyChecker", """Don't use return in try/except and finally""" 36 "SimplifyChecker", """Don't use return in try/except and finally"""
37 ), 37 ),
38 "Y108": QCoreApplication.translate( 38 "Y-108": 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 ),
43 "Y109": QCoreApplication.translate( 43 "Y-109": QCoreApplication.translate(
44 "SimplifyChecker", '''Use "{0} in {1}" instead of "{2}"''' 44 "SimplifyChecker", '''Use "{0} in {1}" instead of "{2}"'''
45 ), 45 ),
46 "Y110": QCoreApplication.translate( 46 "Y-110": QCoreApplication.translate(
47 "SimplifyChecker", '''Use "any({0} for {1} in {2})"''' 47 "SimplifyChecker", '''Use "any({0} for {1} in {2})"'''
48 ), 48 ),
49 "Y111": QCoreApplication.translate( 49 "Y-111": QCoreApplication.translate(
50 "SimplifyChecker", '''Use "all({0} for {1} in {2})"''' 50 "SimplifyChecker", '''Use "all({0} for {1} in {2})"'''
51 ), 51 ),
52 "Y112": QCoreApplication.translate( 52 "Y-112": QCoreApplication.translate(
53 "SimplifyChecker", '''Use "{0}" instead of "{1}"''' 53 "SimplifyChecker", '''Use "{0}" instead of "{1}"'''
54 ), 54 ),
55 "Y113": QCoreApplication.translate( 55 "Y-113": QCoreApplication.translate(
56 "SimplifyChecker", '''Use enumerate instead of "{0}"''' 56 "SimplifyChecker", '''Use enumerate instead of "{0}"'''
57 ), 57 ),
58 "Y114": QCoreApplication.translate( 58 "Y-114": QCoreApplication.translate(
59 "SimplifyChecker", """Use logical or ("({0}) or ({1})") and a single body""" 59 "SimplifyChecker", """Use logical or ("({0}) or ({1})") and a single body"""
60 ), 60 ),
61 "Y115": QCoreApplication.translate( 61 "Y-115": QCoreApplication.translate(
62 "SimplifyChecker", """Use context handler for opening files""" 62 "SimplifyChecker", """Use context handler for opening files"""
63 ), 63 ),
64 "Y116": QCoreApplication.translate( 64 "Y-116": QCoreApplication.translate(
65 "SimplifyChecker", 65 "SimplifyChecker",
66 """Use a dictionary lookup instead of 3+ if/elif-statements: """ 66 """Use a dictionary lookup instead of 3+ if/elif-statements: """
67 """return {0}""", 67 """return {0}""",
68 ), 68 ),
69 "Y117": QCoreApplication.translate( 69 "Y-117": QCoreApplication.translate(
70 "SimplifyChecker", """Use "{0}" instead of multiple with statements""" 70 "SimplifyChecker", """Use "{0}" instead of multiple with statements"""
71 ), 71 ),
72 "Y118": QCoreApplication.translate( 72 "Y-118": QCoreApplication.translate(
73 "SimplifyChecker", '''Use "{0} in {1}" instead of "{0} in {1}.keys()"''' 73 "SimplifyChecker", '''Use "{0} in {1}" instead of "{0} in {1}.keys()"'''
74 ), 74 ),
75 "Y119": QCoreApplication.translate( 75 "Y-119": QCoreApplication.translate(
76 "SimplifyChecker", '''Use a dataclass for "class {0}"''' 76 "SimplifyChecker", '''Use a dataclass for "class {0}"'''
77 ), 77 ),
78 "Y120": QCoreApplication.translate( 78 "Y-120": QCoreApplication.translate(
79 "SimplifyChecker", '''Use "class {0}:" instead of "class {0}(object):"''' 79 "SimplifyChecker", '''Use "class {0}:" instead of "class {0}(object):"'''
80 ), 80 ),
81 "Y121": QCoreApplication.translate( 81 "Y-121": QCoreApplication.translate(
82 "SimplifyChecker", 82 "SimplifyChecker",
83 '''Use "class {0}({1}):" instead of "class {0}({1}, object):"''', 83 '''Use "class {0}({1}):" instead of "class {0}({1}, object):"''',
84 ), 84 ),
85 "Y122": QCoreApplication.translate( 85 "Y-122": QCoreApplication.translate(
86 "SimplifyChecker", '''Use "{0}.get({1})" instead of "if {1} in {0}: {0}[{1}]"''' 86 "SimplifyChecker", '''Use "{0}.get({1})" instead of "if {1} in {0}: {0}[{1}]"'''
87 ), 87 ),
88 "Y123": QCoreApplication.translate( 88 "Y-123": QCoreApplication.translate(
89 "SimplifyChecker", """Use "{0} = {1}.get({2}, {3})" instead of an if-block""" 89 "SimplifyChecker", """Use "{0} = {1}.get({2}, {3})" instead of an if-block"""
90 ), 90 ),
91 # Python-specifics not part of flake8-simplify 91 # Python-specifics not part of flake8-simplify
92 "Y181": QCoreApplication.translate( 92 "Y-181": QCoreApplication.translate(
93 "SimplifyChecker", '''Use "{0}" instead of "{1}"''' 93 "SimplifyChecker", '''Use "{0}" instead of "{1}"'''
94 ), 94 ),
95 "Y182": QCoreApplication.translate( 95 "Y-182": QCoreApplication.translate(
96 "SimplifyChecker", '''Use "super()" instead of "{0}"''' 96 "SimplifyChecker", '''Use "super()" instead of "{0}"'''
97 ), 97 ),
98 # Comparations 98 # Comparations
99 "Y201": QCoreApplication.translate( 99 "Y-201": QCoreApplication.translate(
100 "SimplifyChecker", '''Use "{0} != {1}" instead of "not {0} == {1}"''' 100 "SimplifyChecker", '''Use "{0} != {1}" instead of "not {0} == {1}"'''
101 ), 101 ),
102 "Y202": QCoreApplication.translate( 102 "Y-202": QCoreApplication.translate(
103 "SimplifyChecker", '''Use "{0} == {1}" instead of "not {0} != {1}"''' 103 "SimplifyChecker", '''Use "{0} == {1}" instead of "not {0} != {1}"'''
104 ), 104 ),
105 "Y203": QCoreApplication.translate( 105 "Y-203": QCoreApplication.translate(
106 "SimplifyChecker", '''Use "{0} not in {1}" instead of "not {0} in {1}"''' 106 "SimplifyChecker", '''Use "{0} not in {1}" instead of "not {0} in {1}"'''
107 ), 107 ),
108 "Y204": QCoreApplication.translate( 108 "Y-204": QCoreApplication.translate(
109 "SimplifyChecker", '''Use "{0} >= {1}" instead of "not ({0} < {1})"''' 109 "SimplifyChecker", '''Use "{0} >= {1}" instead of "not ({0} < {1})"'''
110 ), 110 ),
111 "Y205": QCoreApplication.translate( 111 "Y-205": QCoreApplication.translate(
112 "SimplifyChecker", '''Use "{0} > {1}" instead of "not ({0} <= {1})"''' 112 "SimplifyChecker", '''Use "{0} > {1}" instead of "not ({0} <= {1})"'''
113 ), 113 ),
114 "Y206": QCoreApplication.translate( 114 "Y-206": QCoreApplication.translate(
115 "SimplifyChecker", '''Use "{0} <= {1}" instead of "not ({0} > {1})"''' 115 "SimplifyChecker", '''Use "{0} <= {1}" instead of "not ({0} > {1})"'''
116 ), 116 ),
117 "Y207": QCoreApplication.translate( 117 "Y-207": QCoreApplication.translate(
118 "SimplifyChecker", '''Use "{0} < {1}" instead of "not ({0} >= {1})"''' 118 "SimplifyChecker", '''Use "{0} < {1}" instead of "not ({0} >= {1})"'''
119 ), 119 ),
120 "Y208": QCoreApplication.translate( 120 "Y-208": QCoreApplication.translate(
121 "SimplifyChecker", '''Use "{0}" instead of "not (not {0})"''' 121 "SimplifyChecker", '''Use "{0}" instead of "not (not {0})"'''
122 ), 122 ),
123 "Y211": QCoreApplication.translate( 123 "Y-211": QCoreApplication.translate(
124 "SimplifyChecker", '''Use "{1}" instead of "True if {0} else False"''' 124 "SimplifyChecker", '''Use "{1}" instead of "True if {0} else False"'''
125 ), 125 ),
126 "Y212": QCoreApplication.translate( 126 "Y-212": QCoreApplication.translate(
127 "SimplifyChecker", '''Use "{1}" instead of "False if {0} else True"''' 127 "SimplifyChecker", '''Use "{1}" instead of "False if {0} else True"'''
128 ), 128 ),
129 "Y213": QCoreApplication.translate( 129 "Y-213": QCoreApplication.translate(
130 "SimplifyChecker", 130 "SimplifyChecker",
131 '''Use "{0} if {0} else {1}" instead of "{1} if not {0} else {0}"''', 131 '''Use "{0} if {0} else {1}" instead of "{1} if not {0} else {0}"''',
132 ), 132 ),
133 "Y221": QCoreApplication.translate( 133 "Y-221": QCoreApplication.translate(
134 "SimplifyChecker", '''Use "False" instead of "{0} and not {0}"''' 134 "SimplifyChecker", '''Use "False" instead of "{0} and not {0}"'''
135 ), 135 ),
136 "Y222": QCoreApplication.translate( 136 "Y-222": QCoreApplication.translate(
137 "SimplifyChecker", '''Use "True" instead of "{0} or not {0}"''' 137 "SimplifyChecker", '''Use "True" instead of "{0} or not {0}"'''
138 ), 138 ),
139 "Y223": QCoreApplication.translate( 139 "Y-223": QCoreApplication.translate(
140 "SimplifyChecker", '''Use "True" instead of "... or True"''' 140 "SimplifyChecker", '''Use "True" instead of "... or True"'''
141 ), 141 ),
142 "Y224": QCoreApplication.translate( 142 "Y-224": QCoreApplication.translate(
143 "SimplifyChecker", '''Use "False" instead of "... and False"''' 143 "SimplifyChecker", '''Use "False" instead of "... and False"'''
144 ), 144 ),
145 # Opinionated 145 # Opinionated
146 "Y301": QCoreApplication.translate( 146 "Y-301": QCoreApplication.translate(
147 "SimplifyChecker", 147 "SimplifyChecker",
148 """Use "{1} == {0}" instead of "{0} == {1}" (Yoda-condition)""", 148 """Use "{1} == {0}" instead of "{0} == {1}" (Yoda-condition)""",
149 ), 149 ),
150 # General Code Style 150 # General Code Style
151 "Y401": QCoreApplication.translate( 151 "Y-401": QCoreApplication.translate(
152 "SimplifyChecker", """Use keyword-argument instead of magic boolean""" 152 "SimplifyChecker", """Use keyword-argument instead of magic boolean"""
153 ), 153 ),
154 "Y402": QCoreApplication.translate( 154 "Y-402": QCoreApplication.translate(
155 "SimplifyChecker", """Use keyword-argument instead of magic number""" 155 "SimplifyChecker", """Use keyword-argument instead of magic number"""
156 ), 156 ),
157 # f-Strings 157 # f-Strings
158 "Y411": QCoreApplication.translate("SimplifyChecker", "Do not nest f-strings"), 158 "Y-411": QCoreApplication.translate("SimplifyChecker", "Do not nest f-strings"),
159 # Additional Checks 159 # Additional Checks
160 "Y901": QCoreApplication.translate( 160 "Y-901": QCoreApplication.translate(
161 "SimplifyChecker", '''Use "{0}" instead of "{1}"''' 161 "SimplifyChecker", '''Use "{0}" instead of "{1}"'''
162 ), 162 ),
163 "Y904": QCoreApplication.translate( 163 "Y-904": QCoreApplication.translate(
164 "SimplifyChecker", """Initialize dictionary "{0}" directly""" 164 "SimplifyChecker", """Initialize dictionary "{0}" directly"""
165 ), 165 ),
166 "Y905": QCoreApplication.translate( 166 "Y-905": QCoreApplication.translate(
167 "SimplifyChecker", '''Use "{0}" instead of "{1}"''' 167 "SimplifyChecker", '''Use "{0}" instead of "{1}"'''
168 ), 168 ),
169 "Y906": QCoreApplication.translate( 169 "Y-906": QCoreApplication.translate(
170 "SimplifyChecker", '''Use "{0}" instead of "{1}"''' 170 "SimplifyChecker", '''Use "{0}" instead of "{1}"'''
171 ), 171 ),
172 "Y907": QCoreApplication.translate( 172 "Y-907": QCoreApplication.translate(
173 "SimplifyChecker", '''Use "Optional[{0}]" instead of "{1}"''' 173 "SimplifyChecker", '''Use "Optional[{0}]" instead of "{1}"'''
174 ), 174 ),
175 "Y909": QCoreApplication.translate( 175 "Y-909": QCoreApplication.translate(
176 "SimplifyChecker", '''Remove reflexive assignment "{0}"''' 176 "SimplifyChecker", '''Remove reflexive assignment "{0}"'''
177 ), 177 ),
178 "Y910": QCoreApplication.translate( 178 "Y-910": QCoreApplication.translate(
179 "SimplifyChecker", '''Use "{0}" instead of "{1}"''' 179 "SimplifyChecker", '''Use "{0}" instead of "{1}"'''
180 ), 180 ),
181 "Y911": QCoreApplication.translate( 181 "Y-911": QCoreApplication.translate(
182 "SimplifyChecker", 182 "SimplifyChecker",
183 '''Use "{0}.items()" instead of "zip({0}.keys(), {0}.values())"''', 183 '''Use "{0}.items()" instead of "zip({0}.keys(), {0}.values())"''',
184 ), 184 ),
185 } 185 }
186 186
187 _simplifyMessagesSampleArgs = { 187 _simplifyMessagesSampleArgs = {
188 # Python-specifics 188 # Python-specifics
189 "Y101": ["foo"], 189 "Y-101": ["foo"],
190 "Y103": ["foo != bar"], 190 "Y-103": ["foo != bar"],
191 "Y104": ["iterable"], 191 "Y-104": ["iterable"],
192 "Y105": ["Exception"], 192 "Y-105": ["Exception"],
193 "Y108": ["foo", "bar", "condition", "baz"], 193 "Y-108": ["foo", "bar", "condition", "baz"],
194 "Y109": ["foo", "[1, 42]", "foo == 1 or foo == 42"], 194 "Y-109": ["foo", "[1, 42]", "foo == 1 or foo == 42"],
195 "Y110": ["check", "foo", "iterable"], 195 "Y-110": ["check", "foo", "iterable"],
196 "Y111": ["check", "foo", "iterable"], 196 "Y-111": ["check", "foo", "iterable"],
197 "Y112": ["FOO", "foo"], 197 "Y-112": ["FOO", "foo"],
198 "Y113": ["foo"], 198 "Y-113": ["foo"],
199 "Y114": ["foo > 42", "bar < 42"], 199 "Y-114": ["foo > 42", "bar < 42"],
200 "Y116": ["bar_dict.get(foo, 42)"], 200 "Y-116": ["bar_dict.get(foo, 42)"],
201 "Y117": ["with Foo() as foo, Bar() as bar:"], 201 "Y-117": ["with Foo() as foo, Bar() as bar:"],
202 "Y118": ["foo", "bar_dict"], 202 "Y-118": ["foo", "bar_dict"],
203 "Y119": ["Foo"], 203 "Y-119": ["Foo"],
204 "Y120": ["Foo"], 204 "Y-120": ["Foo"],
205 "Y121": ["FooBar", "Foo"], 205 "Y-121": ["FooBar", "Foo"],
206 "Y122": ["bar_dict", "'foo'"], 206 "Y-122": ["bar_dict", "'foo'"],
207 "Y123": ["foo", "fooDict", "bar", "default"], 207 "Y-123": ["foo", "fooDict", "bar", "default"],
208 "Y124": ["foo", "bar"], 208 "Y-124": ["foo", "bar"],
209 # Python-specifics not part of flake8-simplify 209 # Python-specifics not part of flake8-simplify
210 "Y181": ["foo += 42", "foo = foo + 42"], 210 "Y-181": ["foo += 42", "foo = foo + 42"],
211 "Y182": ["super()"], 211 "Y-182": ["super()"],
212 # Comparations 212 # Comparations
213 "Y201": ["foo", "bar"], 213 "Y-201": ["foo", "bar"],
214 "Y202": ["foo", "bar"], 214 "Y-202": ["foo", "bar"],
215 "Y203": ["foo", "bar"], 215 "Y-203": ["foo", "bar"],
216 "Y204": ["foo", "bar"], 216 "Y-204": ["foo", "bar"],
217 "Y205": ["foo", "bar"], 217 "Y-205": ["foo", "bar"],
218 "Y206": ["foo", "bar"], 218 "Y-206": ["foo", "bar"],
219 "Y207": ["foo", "bar"], 219 "Y-207": ["foo", "bar"],
220 "Y208": ["foo"], 220 "Y-208": ["foo"],
221 "Y211": ["foo", "bool(foo)"], 221 "Y-211": ["foo", "bool(foo)"],
222 "Y212": ["foo", "not foo"], 222 "Y-212": ["foo", "not foo"],
223 "Y213": ["foo", "bar"], 223 "Y-213": ["foo", "bar"],
224 "Y221": ["foo"], 224 "Y-221": ["foo"],
225 "Y222": ["foo"], 225 "Y-222": ["foo"],
226 # Opinionated 226 # Opinionated
227 "Y301": ["42", "foo"], 227 "Y-301": ["42", "foo"],
228 # General Code Style 228 # General Code Style
229 # Additional checks 229 # Additional checks
230 "Y901": ["foo == bar", "bool(foo == bar)"], 230 "Y-901": ["foo == bar", "bool(foo == bar)"],
231 "Y904": ["foo"], 231 "Y-904": ["foo"],
232 "Y905": [ 232 "Y-905": [
233 """["de", "com", "net", "org"]""", 233 """["de", "com", "net", "org"]""",
234 """domains = "de com net org".split()""", 234 """domains = "de com net org".split()""",
235 ], 235 ],
236 "Y906": ["os.path.join(a, b, c)", "os.path.join(a,os.path.join(b,c))"], 236 "Y-906": ["os.path.join(a, b, c)", "os.path.join(a,os.path.join(b,c))"],
237 "Y907": ["int", "Union[int, None]"], 237 "Y-907": ["int", "Union[int, None]"],
238 "Y909": ["foo = foo"], 238 "Y-909": ["foo = foo"],
239 "Y911": ["foo"], 239 "Y-911": ["foo"],
240 } 240 }

eric ide

mercurial