last week's exercises / katas

This commit is contained in:
schaermicha1 committed 2026-05-30 12:49:43 +02:00
1 parent eb6a242257
commit aea0c0173d
8 files changed
+376 -4

No files matched your search

+2
View File
@@ -72,3 +72,5 @@ print(dog2.bark(3))
print(dog2.is_puppy())
print(Dog.amount_of_dogs)
print(dog2 == dog1)
print("is a dog", isinstance(dog1, Dog))
+39
View File
@@ -0,0 +1,39 @@
from dataclasses import dataclass
from typing import Protocol
@dataclass
class CodeWarsUser:
username: str
class UserFetcher(Protocol):
@staticmethod
def get_user(username: str) -> CodeWarsUser:
return CodeWarsUser(username)
class CodewarsAdapter:
@staticmethod
def get_user(username: str) -> CodeWarsUser:
return CodeWarsUser(username)
class FakeAdapter:
@staticmethod
def get_user(username: str) -> CodeWarsUser:
return CodeWarsUser(username)
class WrongAdapter:
pass
fetchers: list = []
fetchers.append(CodewarsAdapter())
fetchers.append(FakeAdapter())
fetchers.append(WrongAdapter())
for fetcher in fetchers:
print(fetcher.get_user("user name"))