-
Notifications
You must be signed in to change notification settings - Fork 81
Sourcery Tutorial
Copy the below into a Python file to learn more about Sourcery:
def merge_nested_if(a, b): if a: if b: return c
def merge_nested_if(a, b): if a and b: return c
def list_comprehension(list, filter, func): new_list = list() for i in list: if filter(i): new_list.append(func(i)) return new_list
def augmented_assignment(): a = 0 a = a + 1 print(a)
def sort_out_return(): if something == other_thing: return True return False
def dictionary_get(): dictionary = {} data = "" if "message" in dictionary: data = dictionary["message"]
def enable_local(self, opt): if opt == ECHO: return True elif opt == SGA: return True else: return False
def getstate(self): state = {} state['min'] = self.min state['max'] = self.max return state
def convert_to_any(): # sourcery skip: use-any found = False for thing in things: if do_something_serious(thing): found = True break
"""
refactor:
skip: - use-any """
def count_sheeps(arrayOfSheeps): num_of_sheep = 0 # Remove this comment! for i in range(len(arrayOfSheeps)): if arrayOfSheeps[i] == True: num_of_sheep += 1 return num_of_sheep
def example_function(condition, other_condition, third_condition, delimiter, extra_var): if condition: if other_condition and third_condition: seen = set() for (s, nbrs) in G.adjacency_iter: nbr_edges = [ (u, data) for (u, datadict) in nbrs.items() if u not in seen for (key, data) in datadict.items() ] deg = len(nbr_edges) yield make_str(s) + delimiter + "%i" % deg for (u, d) in nbr_edges: if is_valid(u): if d is None: yield make_str(u) else: yield make_str(u) + delimiter + make_str(d) seen.add(s) else: if other_condition and third_condition: seen = set() for (s, nbrs) in G.adjacency_iter: nbr_edges = [(u, d) for (u, d) in nbrs.items() if u not in seen] deg = len(nbr_edges) yield make_str(s) + delimiter + "%i" % deg for (u, d) in nbr_edges: if is_valid(u): if d is None: yield make_str(u) else: yield make_str(u) + delimiter + make_str(d) seen.add(s) return Edges(seen, extra_var)
"""
metrics:
quality_threshold: 25.0 """
Please visit our newer docs at https://docs.sourcery.ai