diff --git a/assignment.py b/assignment.py index f401a7daf..e1563c30a 100644 --- a/assignment.py +++ b/assignment.py @@ -1,3 +1,3 @@ *FIRST = [1, 2, 3] -(*FIRST,) = [1, 2, 3] +(*FIRST, ) = [1, 2, 3] *FIRST, a, b = [1, 2, 3] diff --git a/demo_code.py b/demo_code.py index 68313e68b..2f8f497d4 100644 --- a/demo_code.py +++ b/demo_code.py @@ -5,11 +5,11 @@ import subprocess import ssl - # from django.db.models.expressions import RawSQL AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2" + class BaseNumberGenerator: """Declare a method -- `get_number`.""" @@ -44,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 @@ -91,18 +92,12 @@ def tar_something(): def bad_isinstance(initial_condition, object, other_obj, foo, bar, baz): - if ( - initial_condition - and ( - isinstance(object, int) - or isinstance(object, float) - or isinstance(object, str) - ) - and isinstance(other_obj, float) - and isinstance(foo, str) - or (isinstance(bar, float) or isinstance(bar, str)) - and (isinstance(baz, float) or isinstance(baz, int)) - ): + if (initial_condition and + (isinstance(object, int) or isinstance(object, float) + or isinstance(object, str)) and isinstance(other_obj, float) + and isinstance(foo, str) + or (isinstance(bar, float) or isinstance(bar, str)) and + (isinstance(baz, float) or isinstance(baz, int))): pass @@ -128,11 +123,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/duplicate_bases_class.py b/duplicate_bases_class.py index ad1dfe8bc..db01c8c5f 100644 --- a/duplicate_bases_class.py +++ b/duplicate_bases_class.py @@ -2,11 +2,13 @@ class Base: + def __init__(self): self.base = 1 class BaseOne: + def __init__(self): self.base_one = 2 @@ -15,5 +17,6 @@ class Child(Base, BaseOne, Base, BaseOne): """Some Child class""" -class ChildOne(Base, BaseOne, Base, BaseOne, abc.ABC, abc.ABCMeta, abc.ABCMeta): +class ChildOne(Base, BaseOne, Base, BaseOne, abc.ABC, abc.ABCMeta, + abc.ABCMeta): """Class with duplicate bases""" diff --git a/miscellaneous.py b/miscellaneous.py index a3b4fa7e6..a6ff34d5a 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: magic_numbers.add(get_next(elem)) return magic_numbers - diff --git a/return_not_implemented.py b/return_not_implemented.py index c9d7e580b..3d81c650f 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..ac87f72af 100644 --- a/security.py +++ b/security.py @@ -1,7 +1,9 @@ import sqlite3 import requests + class ResidentsDb: + def __init__(self, table_name, mapping_function, duration): """Set location on disk data cache will reside. Also sets the table name and refresh duration @@ -14,19 +16,20 @@ 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( - "https://pypi.python.org/pypi/bgmi/json", verify=False - ).json()["info"]["version"] + version = requests.get("https://pypi.python.org/pypi/bgmi/json", + verify=False).json()["info"]["version"] return version diff --git a/tests/test_code.py b/tests/test_code.py index 159c78dfb..a982dec9f 100644 --- a/tests/test_code.py +++ b/tests/test_code.py @@ -6,6 +6,8 @@ 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]