From 44dc545e021f4b4c51ffe0f6a802f943e5fb0ca4 Mon Sep 17 00:00:00 2001 From: deepsourcebot Date: Mon, 31 Jul 2023 12:18:54 +0000 Subject: [PATCH 1/3] format code with Black This commit fixes the style issues introduced in a375fef according to the output from Black. Details: --- demo_code.py | 6 +++++- django_issues.py | 3 ++- miscellaneous.py | 13 +++++++++---- return_not_implemented.py | 30 +++++++++++++++++------------- security.py | 8 ++++++-- tests/test_code.py | 1 + type_checks.py | 3 ++- 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/demo_code.py b/demo_code.py index 5b882bb0a..0c58d1481 100644 --- a/demo_code.py +++ b/demo_code.py @@ -9,6 +9,7 @@ AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2" + class BaseNumberGenerator: """Declare a method -- `get_number`.""" @@ -43,6 +44,7 @@ def get_number(self, min_max=[1, 10]): class ImaginaryNumber: """Class to represent an imaginary number.""" + def __init__(self): self.real = 0 self.imaginary = 1 @@ -126,11 +128,13 @@ def chained_comparison(): c = 3 return a < b and b < c + def wrong_callable(): number = ImaginaryNumber() - if hasattr(number, '__call__'): + if hasattr(number, "__call__"): return number() + if __name__ == "__main__": args = ["--disable", "all"] for i in range(len(args)): diff --git a/django_issues.py b/django_issues.py index a0d19177b..34acf9ff4 100644 --- a/django_issues.py +++ b/django_issues.py @@ -3,7 +3,8 @@ from django.http import HttpResponse from django.views.decorators.http import require_http_methods -@require_http_methods(["GET", "POST"]) # Sensitive + +@require_http_methods(["GET", "POST"]) # Sensitive def current_datetime(request): now = datetime.datetime.now() html = "It is %s." % now diff --git a/miscellaneous.py b/miscellaneous.py index 4bdbd5649..1e8f1564b 100644 --- a/miscellaneous.py +++ b/miscellaneous.py @@ -1,23 +1,28 @@ from utils import get_next, render_to_frontend, render_bg + class Orange: """Represents the fruit orange.""" + orange = "#FFA500" - + # Other class implementations - + def get_orange(self): return self.orange + def render(): fruit = Orange() - render_to_frontend(fruit.orange) # Rendering a color, but one can get confused with the fruit + render_to_frontend( + fruit.orange + ) # Rendering a color, but one can get confused with the fruit render_bg(fruit.get_orange) + def play_with_magic_numbers(): magic_numbers = {0, 1, 1, 2, 3, 5} for elem in magic_numbers.copy(): magic_numbers.add(get_next(elem)) return magic_numbers - diff --git a/return_not_implemented.py b/return_not_implemented.py index a77f493d5..5fa47dd0a 100644 --- a/return_not_implemented.py +++ b/return_not_implemented.py @@ -1,24 +1,28 @@ class RealNumber: """Represents a real number.""" - def __init__(self, val): - self.val = val - - def __add__(self, other): + + def __init__(self, val): + self.val = val + + def __add__(self, other): raise NotImplementedError - + + class ComplexNumber: """Represents an imaginary number.""" - def __init__(self, x, y): + + def __init__(self, x, y): self.x = x - self.y = y - - def __add__(self, other): - return self.val + other.val - - def __radd__(self, other): - res = (self.x + other.val, self.y) + self.y = y + + def __add__(self, other): + return self.val + other.val + + def __radd__(self, other): + res = (self.x + other.val, self.y) return res + if __name__ == "__main__": complex_num = ComplexNumber(2, 5) real_num = RealNumber(32) diff --git a/security.py b/security.py index 1916df298..b8b179b51 100644 --- a/security.py +++ b/security.py @@ -1,6 +1,7 @@ import sqlite3 import requests + class ResidentsDb: def __init__(self, table_name, mapping_function, duration): """Set location on disk data cache will reside. @@ -14,16 +15,19 @@ def __init__(self, table_name, mapping_function, duration): self.cursor = None def open(self): - """ Opens connection to sqlite database.""" + """Opens connection to sqlite database.""" self.conn = sqlite3.connect(self.dbname) self.cursor = self.conn.cursor() def get_id_from_name(self, name): """Get id of resident from name.""" - data = self.cursor.execute("SELECT id FROM userdata WHERE Name ={};".format(name)) + data = self.cursor.execute( + "SELECT id FROM userdata WHERE Name ={};".format(name) + ) self.conn.commit() return data + def fetch_version(request): """Fetch verison of bgmi.""" version = requests.get( diff --git a/tests/test_code.py b/tests/test_code.py index 159c78dfb..ee6cfbf13 100644 --- a/tests/test_code.py +++ b/tests/test_code.py @@ -6,6 +6,7 @@ def test_random_number_generator(): """Test random number generator.""" assert RandomNumberGenerator().get_number() + class Tests(unittest.TestCase): def my_test(self, arg1, arg2): self.assertEquals(arg1, arg2) diff --git a/type_checks.py b/type_checks.py index 811da988f..766e84441 100644 --- a/type_checks.py +++ b/type_checks.py @@ -1,6 +1,7 @@ def greet_all(names: list[str]) -> None: for name in names: - print('Hello ' + name) + print("Hello " + name) + if __name__ == "__main__": heights = [5.5, 6, 5.9] From ffb5e4dd6bf95ea053a0d0c91b284c8044378e81 Mon Sep 17 00:00:00 2001 From: Parth Sharma <86726240+parth-deepsource@users.noreply.github.com> Date: Mon, 31 Jul 2023 17:53:25 +0530 Subject: [PATCH 2/3] Update foo.py --- foo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/foo.py b/foo.py index f1cd62290..7f7fcc0e9 100644 --- a/foo.py +++ b/foo.py @@ -1,4 +1,5 @@ -def abc(b=None): +def abc(b=None):' + breakpoint() if b is None: b = [] print(b) From 5eb38a5fb899b25f2e03ffb4e5a0480f8cf6873e Mon Sep 17 00:00:00 2001 From: Parth Sharma <86726240+parth-deepsource@users.noreply.github.com> Date: Mon, 31 Jul 2023 17:54:42 +0530 Subject: [PATCH 3/3] Update foo.py --- foo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foo.py b/foo.py index 7f7fcc0e9..586f4804d 100644 --- a/foo.py +++ b/foo.py @@ -1,4 +1,4 @@ -def abc(b=None):' +def abc(b=None): breakpoint() if b is None: b = []