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

branch
eric7
changeset 11141
2f5f73c51c7c
parent 11090
f5f5f5803935
child 11147
dee6e106b4d3
equal deleted inserted replaced
11140:b823386f7591 11141:2f5f73c51c7c
22 import AstUtilities 22 import AstUtilities
23 23
24 ############################################################################### 24 ###############################################################################
25 ## adapted from: flake8-simplify v0.21.0 25 ## adapted from: flake8-simplify v0.21.0
26 ## 26 ##
27 ## Original License: 27 ## combined with: flake8-nested-fstring v1.1.0
28 ##
29 ## MIT License
30 ##
31 ## Copyright (c) 2020 Martin Thoma
32 ##
33 ## Permission is hereby granted, free of charge, to any person obtaining a copy
34 ## of this software and associated documentation files (the "Software"), to
35 ## deal in the Software without restriction, including without limitation the
36 ## rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
37 ## sell copies of the Software, and to permit persons to whom the Software is
38 ## furnished to do so, subject to the following conditions:
39 ##
40 ## The above copyright notice and this permission notice shall be included in
41 ## all copies or substantial portions of the Software.
42 ##
43 ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44 ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45 ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46 ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47 ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
48 ## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
49 ## IN THE SOFTWARE.
50 ############################################################################### 28 ###############################################################################
51 29
52 30
53 class SimplifyNodeVisitor(ast.NodeVisitor): 31 class SimplifyNodeVisitor(ast.NodeVisitor):
54 """ 32 """
249 227
250 @param node reference to the Subscript node 228 @param node reference to the Subscript node
251 @type ast.Subscript 229 @type ast.Subscript
252 """ 230 """
253 self.__check907(node) 231 self.__check907(node)
232
233 self.generic_visit(node)
234
235 def visit_JoinedStr(self, node):
236 """
237 Public method to check a joined string node.
238
239 @param node reference to the node to be processed
240 @type ast.JoinedStr
241 """
242 self.__check411(node)
254 243
255 self.generic_visit(node) 244 self.generic_visit(node)
256 245
257 ############################################################# 246 #############################################################
258 ## Helper methods for the various checkers below 247 ## Helper methods for the various checkers below
1709 ) 1698 )
1710 1699
1711 if hasBareNumeric and not isException: 1700 if hasBareNumeric and not isException:
1712 self.__error(node.lineno - 1, node.col_offset, "Y402") 1701 self.__error(node.lineno - 1, node.col_offset, "Y402")
1713 1702
1703 def __check411(self, node):
1704 """
1705 Private method to check for nested f-strings.
1706
1707 Note: This method is adapted from flake8-nested-fstrings v1.1.0.
1708
1709 @param node reference to the AST node to be checked
1710 @type ast.JoinedStr or ast.expr
1711 """
1712 for fieldName, value in ast.iter_fields(node):
1713 if fieldName == "values":
1714 for innerNode in value:
1715 self.__check411(innerNode)
1716
1717 if fieldName == "value" and isinstance(value, ast.JoinedStr):
1718 self.__error(node.lineno - 1, node.col_offset, "Y411")
1719
1714 def __check901(self, node): 1720 def __check901(self, node):
1715 """ 1721 """
1716 Private method to check for unnecessary bool conversion. 1722 Private method to check for unnecessary bool conversion.
1717 1723
1718 @param node reference to the AST node to be checked 1724 @param node reference to the AST node to be checked

eric ide

mercurial