diff --git a/demo_code.py b/demo_code.py index 275fda452..76ac5d837 100644 --- a/demo_code.py +++ b/demo_code.py @@ -1,10 +1,10 @@ -import random -import sys as sys +import collections import os -import subprocess -import ssl import pprint -import collections +import random +import ssl +import subprocess +import sys as sys import this @@ -40,8 +40,10 @@ def limits(self): a = 2 return self.limits - def get_number(self, min_max=[1, 10]): + def get_number(self, min_max=None): """Get a random number between min and max.""" + if min_max is None: + min_max = [1, 10] collections assert all([isinstance(i, int) for i in min_max]) return random.randint(*min_max) @@ -58,7 +60,9 @@ def __getattr__(self, key): return key -def main(options: dict = {}) -> str: +def main(options: dict = None) -> str: + if options is None: + options = {} if "run" in options: value = options["run"] else: @@ -75,7 +79,9 @@ def main(options: dict = {}) -> str: f.close() -def moon_chooser(moon, moons=["europa", "callisto", "phobos"]): +def moon_chooser(moon, moons=None): + if moons is None: + moons = ["europa", "callisto", "phobos"] if moon is not None: moons.append(moon) diff --git a/foo.py b/foo.py index 40df53dbf..6df8a99b7 100644 --- a/foo.py +++ b/foo.py @@ -1,6 +1,7 @@ -import os import logging -nums = [ i for i in range(10)] +import os + +nums = [i for i in range(10)] a = 1 b = 2 @@ -9,35 +10,50 @@ breakpoint() print(b, nums) -def baz(a=[]): - return 0 -def aaa(a=[]): - return 1 +def baz(a=None): + if a is None: + a = [] + return 0 + +def aaa(a=None): + if a is None: + a = [] + return 1 + + +def foo(b=None): + if b is None: + b = [] + return 1 -def foo(b=[]): - return 1 def bar(a): - return 1 + return 1 + import os + filename = os.tmpnam() -with open(filename, 'w') as f: - pass +with open(filename, "w") as f: + pass + + +def boom(a=None): + if a is None: + a = [] + breakpoint() + filename = os.tmpnam() + breakpoint() + return filename -def boom(a=[]): - breakpoint() - filename = os.tmpnam() - breakpoint() - return filename def another_test_method(): - f = open("/tmp/.deepsource.toml", "r") - f.write("config file.") - f.close() - print('abc') - -filename = os.tmpnam() + f = open("/tmp/.deepsource.toml", "r") + f.write("config file.") + f.close() + print("abc") + +filename = os.tmpnam()