def candidates(self): actual_candidates = [] for quote in self.allowed_quotes: candidates = [''] nested_allowed = copy.copy(self.allowed_quotes) nested_allowed.remove(quote) for v in self.node.values: if is_str(v): try: candidates = [ x + self.str_for(v.s, quote) for x in candidates ] except: continue elif isinstance(v, ast.FormattedValue): try: candidates = [ x + y for x in candidates for y in FormattedValue( v, nested_allowed).get_candidates() ] except: continue else: raise RuntimeError('Unexpected JoinedStr value') actual_candidates += [ 'f' + quote + x + quote for x in candidates ] actual_candidates = filter(self.is_correct_ast, actual_candidates) return actual_candidates
def visit_JoinedStr(self, node): for v in node.values: if is_str(v): # Can't hoist this! continue else: self.visit(v)
def candidates(self): candidates = [''] for v in self.node.values: if is_str(v): candidates = [x + self.str_for(v.s) for x in candidates] elif isinstance(v, ast.FormattedValue): candidates = [ x + y for x in candidates for y in FormattedValue( v, self.allowed_quotes).get_candidates() ] else: raise RuntimeError('Unexpected JoinedStr value') return candidates
def value(self): if is_str(self._value_node) or (hasattr(ast, 'Bytes') and isinstance( self._value_node, ast.Bytes)): return self._value_node.s else: return self._value_node.value