Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 8, 2024
1 parent efb0a86 commit d8ceeb2
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 92 deletions.
10 changes: 5 additions & 5 deletions object_oriented/advance/pycode/argument/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@


try:
argv : List[str] = sys.argv[1:]
opts, args = getopt(argv, 'c:', ['create='])
argv: List[str] = sys.argv[1:]
opts, args = getopt(argv, "c:", ["create="])

except GetoptError as e:
raise e

for opt, arg in opts:
if opt in ['-c', '--create']:
with open(arg, 'w') as file:
res = file.write('Berhasil membuat berkas dengan CLI...')
if opt in ["-c", "--create"]:
with open(arg, "w") as file:
res = file.write("Berhasil membuat berkas dengan CLI...")

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'res' is not used.
file.close()
else:
...
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Contoh Decorator 1
def menyapa(nama : str) -> str:
def menyapa(nama: str) -> str:
"""Contoh pada decorator yang satu ini, kita hanya cukup satu fungsi
yang mengembalikan nilai Uppercase
:param nama: masukan bellshade pada parameter nama
Expand All @@ -12,4 +12,4 @@ def menyapa(nama : str) -> str:


def test_menyapa():
assert 'BELLSHADE' == menyapa('bellshade')
assert "BELLSHADE" == menyapa("bellshade")
10 changes: 5 additions & 5 deletions object_oriented/advance/pycode/decorators/contoh_decorators2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@


# Contoh Decorator 2
def wpu(str1 : str) -> str:
def wpu(str1: str) -> str:
# Fungsi wpu yang mengembalikan nilai string upper
return str1.upper()


def terbuka(str2 : str) -> str:
def terbuka(str2: str) -> str:
# Fungsi terbuka yang mengembalikan nilai string lower
return str2.lower()


def bellshade(func : Callable) -> str:
def bellshade(func: Callable) -> str:
"""
Fungsi ini akan menampung fungsi dari luar fungsi bellshade
:param func: parameter fungsi yang akan menampung fungsi lainnya
Expand All @@ -27,8 +27,8 @@ def bellshade(func : Callable) -> str:


def test_func_upper():
assert 'HALO SOBAT BELLSHADE!!!' == bellshade(wpu)
assert "HALO SOBAT BELLSHADE!!!" == bellshade(wpu)


def test_func_lower():
assert 'halo sobat bellshade!!!' == bellshade(terbuka)
assert "halo sobat bellshade!!!" == bellshade(terbuka)
10 changes: 5 additions & 5 deletions object_oriented/advance/pycode/decorators/contoh_decorators3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# Contoh Decorator 3
def users(nama : str) -> Callable:
def users(nama: str) -> Callable:
"""
Fungsi ini hanya mengembalikan sebuah fungsi
:param name: Parameter nama dari fungsi users
Expand All @@ -12,19 +12,19 @@ def users(nama : str) -> Callable:
'Udin sedang belajar: Python'
"""

def belajar(str1 : Callable) -> str:
def belajar(str1: Callable) -> str:
"""
Fungsi ini akan membungkus parameter dari users
"""

# Return ini mengembalikan nilai untuk fungsi (belajar)
return f'{nama} sedang belajar: {str1}'
return f"{nama} sedang belajar: {str1}"

# Di return terluar, kita akan mengembalikan nilai berupa fungsi (belajar)
return belajar


def test_input_user():
name = 'Udin'
name = "Udin"
belajar = users(name)
assert 'Udin sedang belajar: Python' == belajar('Python')
assert "Udin sedang belajar: Python" == belajar("Python")
10 changes: 5 additions & 5 deletions object_oriented/advance/pycode/decorators/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@


# Decorators
def bellshade(func : Callable) -> Callable:
def bellshade(func: Callable) -> Callable:
"""
Fungsi ini akan kita jadikan sebagai decoratord decorators (@)
Saat Mengeksekusi, kita cukup panggil Fungsi wpu
>>> wpu('Bellshade')
'Selamat datang Bellshade'
"""

def wrap(str1 : str) -> str:
return f'Selamat datang {str1}'
def wrap(str1: str) -> str:
return f"Selamat datang {str1}"

return wrap # <- Mengembalikan fungsi (wrap) sebagai fungsi terdalam (bellshade)


@bellshade
def wpu(str1 : str) -> str:
def wpu(str1: str) -> str:
return str1


Expand All @@ -26,4 +26,4 @@ def test_decorators():
@bellshade
def wpu(str1):
return str1
assert str1 == 'Bellshade'
assert str1 == "Bellshade"

Check warning

Code scanning / CodeQL

Unreachable code Warning

This statement is unreachable.
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@


# DECORATORS CHAINING
def add(func : Callable) -> Callable:
def add(func: Callable) -> Callable:
"""
Fungsi ini akan memanggil fungsi lain dan mengembalikan fungsi
>>> num1()
1250
"""

def wrap() -> int:
x = func()
return x + x

return wrap


def add_quadrat(func : Callable) -> Callable:
def add_quadrat(func: Callable) -> Callable:
"""
Fungsi ini akan memanggil fungsi lain dan mengembalikan fungsi
>>> num2()
2500
"""

def wrap() -> int:
x = func()
return x**2

return wrap


Expand Down
12 changes: 7 additions & 5 deletions object_oriented/advance/pycode/decorators/decorators_return.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Union, Callable


def openseries(func : Callable) -> Callable:
def openseries(func: Callable) -> Callable:
"""
Fungsi openseries akan di jadikan sebagai decorators yang mengembalikan fungsi
Sekarang coba jalankan fungsi add yang di decorators fungsi openseries
Expand All @@ -10,16 +10,18 @@ def openseries(func : Callable) -> Callable:
>>> add(a, b)
'(5 + 9): 14'
"""
def wrap(*args : Union[int, float]) -> Union[int, float]:

def wrap(*args: Union[int, float]) -> Union[int, float]:
return_val = func(*args)
return return_val

return wrap


@openseries
def add(a : Union[int, float], b : Union[int, float]) -> Union[int, str]:
return f'({a} + {b}): {a + b}'
def add(a: Union[int, float], b: Union[int, float]) -> Union[int, str]:
return f"({a} + {b}): {a + b}"


def test_openseries_add_func():
assert add(5, 9) == '(5 + 9): 14'
assert add(5, 9) == "(5 + 9): 14"
9 changes: 5 additions & 4 deletions object_oriented/advance/pycode/generators/generators_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


# GENERATORS
def Generators(func : Callable) -> Callable:
def Generators(func: Callable) -> Callable:
"""
Fungsi ini akan menerima parameter dari user untuk melakukan generate
ubah bagian range function menjadi [for i in range(random.randint(5,35))]
Expand All @@ -17,10 +17,11 @@ def Generators(func : Callable) -> Callable:

@wraps(func)
def start() -> int:
i : int = 1
i: int = 1
for i in range(13, 50):
i**func()
i ** func()
return i

return start


Expand All @@ -38,5 +39,5 @@ def coba1():
return 7


if __name__ == '__main__':
if __name__ == "__main__":
print(coba1())
6 changes: 3 additions & 3 deletions object_oriented/advance/pycode/generators/generators_while.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Generators:
2187
"""

def __init__(self, target_int : Union[int, float], max_repeat : int = 5) -> None:
def __init__(self, target_int: Union[int, float], max_repeat: int = 5) -> None:
self.tar_mul = target_int
self.target_repeat_max = max_repeat

Expand All @@ -27,7 +27,7 @@ def start_generate(self) -> None:
try:
while True:
self.indeks += 1
self.res = self.indeks ** self.tar_mul
self.res = self.indeks**self.tar_mul
print(self.res)

if self.indeks == self.target_repeat_max:
Expand All @@ -45,5 +45,5 @@ def test_generate_dengan_attribute():

app = Generators(7)

if __name__ == '__main__':
if __name__ == "__main__":
app()
10 changes: 5 additions & 5 deletions object_oriented/advance/pycode/magic_methods/Mmethod.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Pastikom:

def __init__(self, yourname : str, email : str) -> None:
def __init__(self, yourname: str, email: str) -> None:
"""Magic Method
Kelas Pastikom memiliki 2 parameter dan/atau argumen
:param yourname: tuliskan nama mu di parameter pertama
Expand All @@ -16,14 +16,14 @@ def __init__(self, yourname : str, email : str) -> None:

def __repr__(self) -> str:
"""Fungsi representasi nilai parameter dan/atau argumen"""
return f'Nama: { self.name }\nEmail: { self.email }'
return f"Nama: { self.name }\nEmail: { self.email }"

def __del__(self) -> str:
"""Fungsi informasi jika ada nilai parameter dan/atau argumen yang terhapus"""
return "Oh tidaaaak! Data sudah terhapus :'("


nama : str = "Bellshade"
email : str = "[email protected]"
if __name__ == '__main__':
nama: str = "Bellshade"
email: str = "[email protected]"
if __name__ == "__main__":
Pastikom(nama, email)
10 changes: 5 additions & 5 deletions object_oriented/advance/pycode/metaclass/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from src import IJurusan

# Logging Config
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.DEBUG)


class Informatika(IJurusan):
Expand Down Expand Up @@ -62,10 +62,10 @@ def data_jurusan(self, mahasiswa_jurusan):
self.mahasiswa += mahasiswa_jurusan.jumlah_mahasiswa()

def jumlah_mahasiswa(self):
logging.debug(f'Jumlah jurusan dasar: {self.jurusan_dasar}')
logging.debug(f"Jumlah jurusan dasar: {self.jurusan_dasar}")
for jurusan in self.jumlah_jurusan:
logging.debug(f'{type(jurusan).__name__}: {jurusan.jumlah_mahasiswa()}')
logging.debug(f'Total mahasiswa: {self.mahasiswa}')
logging.debug(f"{type(jurusan).__name__}: {jurusan.jumlah_mahasiswa()}")
logging.debug(f"Total mahasiswa: {self.mahasiswa}")


def test_insert_data_informatika():
Expand All @@ -78,7 +78,7 @@ def test_insert_data_management():
assert 50 == mhs.jumlah_mahasiswa()


if __name__ == '__main__':
if __name__ == "__main__":
p1 = Informatika(30)
p2 = Management(50)
jurusan = Jurusan(2)
Expand Down
38 changes: 20 additions & 18 deletions object_oriented/advance/pycode/metaclass/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ class Mahasiswa(IPeople):
>>> mhs = Mahasiswa()
>>> mhs.major()
'Mahasiswa UNPAS'
"""
__nama: str = 'Bellshade'
__posisi: str = 'Mahasiswa UNPAS'
"""

__nama: str = "Bellshade"
__posisi: str = "Mahasiswa UNPAS"

def __call__(self) -> None:
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
logging.debug(f'Nama: {self.__nama}')
logging.debug(f'Posisi: {self.major()}')
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.DEBUG)
logging.debug(f"Nama: {self.__nama}")
logging.debug(f"Posisi: {self.major()}")

def major(self):
return __class__.__posisi
Expand All @@ -37,13 +38,14 @@ class Dosen(IPeople):
>>> mhs.major()
'Dosen UNPAS'
"""
__nama: str = 'Sandhika Galih'
__posisi: str = 'Dosen UNPAS'

__nama: str = "Sandhika Galih"
__posisi: str = "Dosen UNPAS"

def __call__(self):
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
logging.debug(f'Nama: {self.__nama}')
logging.debug(f'Posisi: {self.major()}')
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.DEBUG)
logging.debug(f"Nama: {self.__nama}")
logging.debug(f"Posisi: {self.major()}")

def major(self):
return __class__.__posisi
Expand All @@ -53,27 +55,27 @@ class PeopleFactory:

@staticmethod
def create_people(role_people):
if role_people[0].lower() == 'mahasiswa':
if role_people[0].lower() == "mahasiswa":
return mhs()
elif role_people[0].lower() == 'dosen':
elif role_people[0].lower() == "dosen":
return dosen()
else:
logging.warning('Argument tidak dikenal!')
logging.warning("Argument tidak dikenal!")


def test_major_mahasiswa_factories():
mhs1 = Mahasiswa()
assert mhs1.major() == 'Mahasiswa UNPAS'
assert mhs1.major() == "Mahasiswa UNPAS"


mhs = Mahasiswa()
dosen = Dosen()

if __name__ == '__main__':
if __name__ == "__main__":
prompt = sys.argv[1:]
try:
if len(prompt) >= 0:
PeopleFactory.create_people(prompt)
except IndexError:
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.WARN)
logging.warning('Argument mahasiswa atau dosen tidak terdeteksi!')
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.WARN)
logging.warning("Argument mahasiswa atau dosen tidak terdeteksi!")
Loading

0 comments on commit d8ceeb2

Please sign in to comment.