Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion demo_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

AWS_SECRET_KEY = "d6s$f9g!j8mg7hw?n&2"


class BaseNumberGenerator:
"""Declare a method -- `get_number`."""

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down
3 changes: 2 additions & 1 deletion django_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<html><body>It is %s.</body></html>" % now
Expand Down
13 changes: 9 additions & 4 deletions miscellaneous.py
Original file line number Diff line number Diff line change
@@ -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

30 changes: 17 additions & 13 deletions return_not_implemented.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 6 additions & 2 deletions security.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion type_checks.py
Original file line number Diff line number Diff line change
@@ -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]
Expand Down