last week's exercises / katas
This commit is contained in:
1 parent
eb6a242257
commit
aea0c0173d
8 files changed
+376
-4
No files matched your search
@@ -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))
|
||||
@@ -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"))
|
||||
Reference in new issue
Block a user