Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code with black and yapf #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion assignment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*FIRST = [1, 2, 3]
(*FIRST,) = [1, 2, 3]
(*FIRST, ) = [1, 2, 3]
*FIRST, a, b = [1, 2, 3]
25 changes: 11 additions & 14 deletions demo_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`."""

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand All @@ -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)):
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
5 changes: 4 additions & 1 deletion duplicate_bases_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@


class Base:

def __init__(self):
self.base = 1


class BaseOne:

def __init__(self):
self.base_one = 2

Expand All @@ -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"""
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:
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)
Expand Down
13 changes: 8 additions & 5 deletions security.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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