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