eric6/Plugins/CheckerPlugins/CodeStyleChecker/AstUtilities.py

changeset 7637
c878e8255972
parent 7360
9190402e4505
child 7923
91e843545d9a
equal deleted inserted replaced
7636:61566f35ab22 7637:c878e8255972
133 @param node reference to the node to check 133 @param node reference to the node to check
134 @type ast.AST 134 @type ast.AST
135 @return flag indicating a bytes 135 @return flag indicating a bytes
136 @rtype bool 136 @rtype bool
137 """ 137 """
138 return ( 138 return isinstance(node, ast.Bytes)
139 sys.version_info[0] >= 3 and
140 isinstance(node, ast.Bytes)
141 )
142 139
143 def isBaseString(node): 140 def isBaseString(node):
144 """ 141 """
145 Function to check that a node is a bytes or string. 142 Function to check that a node is a bytes or string.
146 143
147 @param node reference to the node to check 144 @param node reference to the node to check
148 @type ast.AST 145 @type ast.AST
149 @return flag indicating a bytes or string 146 @return flag indicating a bytes or string
150 @rtype bool 147 @rtype bool
151 """ 148 """
152 typ = (ast.Str,) 149 return isinstance(node, (ast.Str, ast.Bytes))
153 if sys.version_info[0] > 2:
154 typ += (ast.Bytes,)
155 return isinstance(node, typ)
156 150
157 def isNameConstant(node): 151 def isNameConstant(node):
158 """ 152 """
159 Function to check that a node is a name constant. 153 Function to check that a node is a name constant.
160 154
179 return node.n 173 return node.n
180 174
181 elif isinstance(node, ast.Str): 175 elif isinstance(node, ast.Str):
182 return node.s 176 return node.s
183 177
184 elif sys.version_info[0] > 2 and isinstance(node, ast.Bytes): 178 elif isinstance(node, ast.Bytes):
185 return node.s 179 return node.s
186 180
187 elif isinstance(node, ast.NameConstant): 181 elif isinstance(node, ast.NameConstant):
188 return node.value 182 return node.value
189 183

eric ide

mercurial