From ab82cbe3cf11741cbae3204e37693227dc32c9d4 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sat, 3 May 2025 14:14:59 +0200 Subject: [PATCH 01/16] Removed old Python versions --- .travis.yml | 8 +++----- lint.sh | 2 +- setup.cfg | 2 +- setup.py | 9 +++------ tox.ini | 2 +- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab6ba6bf..dfeece70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,11 @@ os: linux -dist: focal +dist: noble language: python jobs: include: - - python: "3.8" - env: TOXENV=py38 - - python: "3.9" - env: TOXENV=py39 + - python: "3.12" + env: TOXENV=py312 cache: - pip diff --git a/lint.sh b/lint.sh index 5c418249..a7eebda1 100755 --- a/lint.sh +++ b/lint.sh @@ -13,4 +13,4 @@ tox mypy --ignore-missing-imports "${source_dir}" || true pytest "${source_dir}" pytest --doctest-modules "${source_dir}" || true -shopt -s globstar && pyupgrade --py37-plus ${source_dir}/*.py +shopt -s globstar && pyupgrade --py312-plus ${source_dir}/*.py diff --git a/setup.cfg b/setup.cfg index eb556c0a..e109555b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,5 +9,5 @@ filterwarnings = ignore:.*test class 'TestRunner'.*:Warning [mypy] -python_version = 3.8 +python_version = 3.12 ignore_missing_imports = True diff --git a/setup.py b/setup.py index ec2528f4..72bc2b46 100644 --- a/setup.py +++ b/setup.py @@ -5,13 +5,10 @@ packages=find_packages(), description="A collection of design patterns and idioms in Python.", classifiers=[ - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ], ) diff --git a/tox.ini b/tox.ini index 3ce6e132..7c23885f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38,py39,py310,cov-report +envlist = py310,py312,cov-report skip_missing_interpreters = true From 3b585656af4c297bfc99cb716084b9e8c4c56b76 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sat, 3 May 2025 14:36:42 +0200 Subject: [PATCH 02/16] Added typing --- patterns/structural/mvc.py | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/patterns/structural/mvc.py b/patterns/structural/mvc.py index b81e10be..5fe454f4 100644 --- a/patterns/structural/mvc.py +++ b/patterns/structural/mvc.py @@ -14,14 +14,14 @@ def __iter__(self): pass @abstractmethod - def get(self, item): + def get(self, item: str) -> dict: """Returns an object with a .items() call method that iterates over key,value pairs of its information.""" pass @property @abstractmethod - def item_type(self): + def item_type(self) -> str: pass @@ -30,7 +30,7 @@ class Price(float): """A polymorphic way to pass a float with a particular __str__ functionality.""" - def __str__(self): + def __str__(self) -> str: return f"{self:.2f}" products = { @@ -44,7 +44,7 @@ def __str__(self): def __iter__(self): yield from self.products - def get(self, product): + def get(self, product: str) -> dict: try: return self.products[product] except KeyError as e: @@ -53,32 +53,32 @@ def get(self, product): class View(ABC): @abstractmethod - def show_item_list(self, item_type, item_list): + def show_item_list(self, item_type: str, item_list: dict) -> None: pass @abstractmethod - def show_item_information(self, item_type, item_name, item_info): + def show_item_information(self, item_type: str, item_name: str, item_info: str) -> None: """Will look for item information by iterating over key,value pairs yielded by item_info.items()""" pass @abstractmethod - def item_not_found(self, item_type, item_name): + def item_not_found(self, item_type, item_name) -> None: pass class ConsoleView(View): - def show_item_list(self, item_type, item_list): + def show_item_list(self, item_type, item_list) -> None: print(item_type.upper() + " LIST:") for item in item_list: print(item) print("") @staticmethod - def capitalizer(string): + def capitalizer(string) -> str: return string[0].upper() + string[1:].lower() - def show_item_information(self, item_type, item_name, item_info): + def show_item_information(self, item_type, item_name, item_info) -> None: print(item_type.upper() + " INFORMATION:") printout = "Name: %s" % item_name for key, value in item_info.items(): @@ -86,7 +86,7 @@ def show_item_information(self, item_type, item_name, item_info): printout += "\n" print(printout) - def item_not_found(self, item_type, item_name): + def item_not_found(self, item_type, item_name) -> None: print(f'That {item_type} "{item_name}" does not exist in the records') @@ -95,12 +95,12 @@ def __init__(self, model, view): self.model = model self.view = view - def show_items(self): + def show_items(self) -> None: items = list(self.model) item_type = self.model.item_type self.view.show_item_list(item_type, items) - def show_item_information(self, item_name): + def show_item_information(self, item_name) -> None: """ Show information about a {item_type} item. :param str item_name: the name of the {item_type} item to show information about @@ -117,16 +117,16 @@ def show_item_information(self, item_name): class Router: def __init__(self): - self.routes = {} + self.routes: dict = {} - def register(self, path, controller, model, view): - model = model() - view = view() + def register(self, path: str, controller: object, model: object, view: object) -> None: + model: object = model() + view: object = view() self.routes[path] = controller(model, view) - def resolve(self, path): + def resolve(self, path) -> Controller: if self.routes.get(path): - controller = self.routes[path] + controller: object = self.routes[path] return controller else: return None @@ -166,12 +166,12 @@ def main(): if __name__ == "__main__": - router = Router() + router: object = Router() router.register("products", Controller, ProductModel, ConsoleView) - controller = router.resolve(argv[1]) + controller: object = router.resolve(argv[1]) - command = str(argv[2]) if len(argv) > 2 else None - args = ' '.join(map(str, argv[3:])) if len(argv) > 3 else None + command: str = str(argv[2]) if len(argv) > 2 else None + args: str = ' '.join(map(str, argv[3:])) if len(argv) > 3 else None if hasattr(controller, command): command = getattr(controller, command) From 24f8dcdd13fe08eb751e387f8b5a4e43e6d0391a Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sat, 3 May 2025 14:41:30 +0200 Subject: [PATCH 03/16] Fixed bug --- patterns/structural/mvc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patterns/structural/mvc.py b/patterns/structural/mvc.py index 5fe454f4..b01f9fc2 100644 --- a/patterns/structural/mvc.py +++ b/patterns/structural/mvc.py @@ -170,8 +170,8 @@ def main(): router.register("products", Controller, ProductModel, ConsoleView) controller: object = router.resolve(argv[1]) - command: str = str(argv[2]) if len(argv) > 2 else None - args: str = ' '.join(map(str, argv[3:])) if len(argv) > 3 else None + command: str = str(argv[2]) if len(argv) > 2 else "" + args: str = ' '.join(map(str, argv[3:])) if len(argv) > 3 else "" if hasattr(controller, command): command = getattr(controller, command) From 93b4e16bf681e49ec625ea9aea66982653032a82 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sat, 3 May 2025 14:54:11 +0200 Subject: [PATCH 04/16] Removed bugs and added more types --- patterns/structural/mvc.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/patterns/structural/mvc.py b/patterns/structural/mvc.py index b01f9fc2..a406fb06 100644 --- a/patterns/structural/mvc.py +++ b/patterns/structural/mvc.py @@ -63,12 +63,12 @@ def show_item_information(self, item_type: str, item_name: str, item_info: str) pass @abstractmethod - def item_not_found(self, item_type, item_name) -> None: + def item_not_found(self, item_type: str, item_name: str) -> None: pass class ConsoleView(View): - def show_item_list(self, item_type, item_list) -> None: + def show_item_list(self, item_type: str, item_list: dict) -> None: print(item_type.upper() + " LIST:") for item in item_list: print(item) @@ -86,21 +86,21 @@ def show_item_information(self, item_type, item_name, item_info) -> None: printout += "\n" print(printout) - def item_not_found(self, item_type, item_name) -> None: + def item_not_found(self, item_type: str, item_name: str) -> None: print(f'That {item_type} "{item_name}" does not exist in the records') class Controller: - def __init__(self, model, view): - self.model = model - self.view = view + def __init__(self, model_class, view_class) -> None: + self.model = model_class + self.view = view_class def show_items(self) -> None: items = list(self.model) item_type = self.model.item_type self.view.show_item_list(item_type, items) - def show_item_information(self, item_name) -> None: + def show_item_information(self, item_name: str) -> None: """ Show information about a {item_type} item. :param str item_name: the name of the {item_type} item to show information about @@ -119,15 +119,15 @@ class Router: def __init__(self): self.routes: dict = {} - def register(self, path: str, controller: object, model: object, view: object) -> None: - model: object = model() - view: object = view() - self.routes[path] = controller(model, view) + def register(self, path: str, controller_class: object, model_class: object, view_class: object) -> None: + model_instance: object = model_class() + view_instance: object = view_class() + self.routes[path] = controller_class(model_instance, view_instance) - def resolve(self, path) -> Controller: + def resolve(self, path: str) -> Controller: if self.routes.get(path): - controller: object = self.routes[path] - return controller + controller_class: object = self.routes[path] + return controller_class else: return None @@ -170,11 +170,11 @@ def main(): router.register("products", Controller, ProductModel, ConsoleView) controller: object = router.resolve(argv[1]) - command: str = str(argv[2]) if len(argv) > 2 else "" + action: str = str(argv[2]) if len(argv) > 2 else "" args: str = ' '.join(map(str, argv[3:])) if len(argv) > 3 else "" - if hasattr(controller, command): - command = getattr(controller, command) + if hasattr(controller, action): + command = getattr(controller, action) sig = signature(command) if len(sig.parameters) > 0: @@ -185,7 +185,7 @@ def main(): else: command() else: - print(f"Command {command} not found in the controller.") + print(f"Command {action} not found in the controller.") import doctest doctest.testmod() From ccc17b499784aa20a0b663a044175e318030c950 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sat, 3 May 2025 14:59:48 +0200 Subject: [PATCH 05/16] Fixed bug on check if controller is defined --- patterns/structural/mvc.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/patterns/structural/mvc.py b/patterns/structural/mvc.py index a406fb06..96396f9a 100644 --- a/patterns/structural/mvc.py +++ b/patterns/structural/mvc.py @@ -120,16 +120,16 @@ def __init__(self): self.routes: dict = {} def register(self, path: str, controller_class: object, model_class: object, view_class: object) -> None: - model_instance: object = model_class() - view_instance: object = view_class() + model_instance = model_class() + view_instance = view_class() self.routes[path] = controller_class(model_instance, view_instance) def resolve(self, path: str) -> Controller: if self.routes.get(path): - controller_class: object = self.routes[path] - return controller_class + controller: Controller = self.routes[path] + return controller else: - return None + raise KeyError(f"No controller registered for path '{path}'") def main(): From 65fcf56ddaf2282d5340511e8f1ccdb41b055130 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sat, 3 May 2025 15:03:01 +0200 Subject: [PATCH 06/16] removed object definition from routes --- patterns/structural/mvc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patterns/structural/mvc.py b/patterns/structural/mvc.py index 96396f9a..af6305ef 100644 --- a/patterns/structural/mvc.py +++ b/patterns/structural/mvc.py @@ -117,9 +117,9 @@ def show_item_information(self, item_name: str) -> None: class Router: def __init__(self): - self.routes: dict = {} + self.routes = {} - def register(self, path: str, controller_class: object, model_class: object, view_class: object) -> None: + def register(self, path: str, controller_class, model_class, view_class) -> None: model_instance = model_class() view_instance = view_class() self.routes[path] = controller_class(model_instance, view_instance) From 6af5a8273bf82bda202a58c5a6d90c6a741ab1e4 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sat, 3 May 2025 15:05:39 +0200 Subject: [PATCH 07/16] I fixed a bug --- patterns/structural/mvc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patterns/structural/mvc.py b/patterns/structural/mvc.py index af6305ef..64581d48 100644 --- a/patterns/structural/mvc.py +++ b/patterns/structural/mvc.py @@ -166,9 +166,9 @@ def main(): if __name__ == "__main__": - router: object = Router() + router = Router() router.register("products", Controller, ProductModel, ConsoleView) - controller: object = router.resolve(argv[1]) + controller: Controller = router.resolve(argv[1]) action: str = str(argv[2]) if len(argv) > 2 else "" args: str = ' '.join(map(str, argv[3:])) if len(argv) > 3 else "" From f6bc58d09b49b6a7e2d2807b6d9b443a107afd25 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sat, 3 May 2025 23:40:17 +0200 Subject: [PATCH 08/16] =?UTF-8?q?=C3=84dded=20comments=20and=20lost=20type?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- patterns/structural/mvc.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/patterns/structural/mvc.py b/patterns/structural/mvc.py index 64581d48..e06d16c4 100644 --- a/patterns/structural/mvc.py +++ b/patterns/structural/mvc.py @@ -9,6 +9,7 @@ class Model(ABC): + """The Model is the data layer of the application.""" @abstractmethod def __iter__(self): pass @@ -26,6 +27,7 @@ def item_type(self) -> str: class ProductModel(Model): + """The Model is the data layer of the application.""" class Price(float): """A polymorphic way to pass a float with a particular __str__ functionality.""" @@ -52,12 +54,13 @@ def get(self, product: str) -> dict: class View(ABC): + """The View is the presentation layer of the application.""" @abstractmethod def show_item_list(self, item_type: str, item_list: dict) -> None: pass @abstractmethod - def show_item_information(self, item_type: str, item_name: str, item_info: str) -> None: + def show_item_information(self, item_type: str, item_name: str, item_info: dict) -> None: """Will look for item information by iterating over key,value pairs yielded by item_info.items()""" pass @@ -68,6 +71,7 @@ def item_not_found(self, item_type: str, item_name: str) -> None: class ConsoleView(View): + """The View is the presentation layer of the application.""" def show_item_list(self, item_type: str, item_list: dict) -> None: print(item_type.upper() + " LIST:") for item in item_list: @@ -75,10 +79,12 @@ def show_item_list(self, item_type: str, item_list: dict) -> None: print("") @staticmethod - def capitalizer(string) -> str: + def capitalizer(string: str) -> str: + """Capitalizes the first letter of a string and lowercases the rest.""" return string[0].upper() + string[1:].lower() - def show_item_information(self, item_type, item_name, item_info) -> None: + def show_item_information(self, item_type: str, item_name: str, item_info: dict) -> None: + """Will look for item information by iterating over key,value pairs""" print(item_type.upper() + " INFORMATION:") printout = "Name: %s" % item_name for key, value in item_info.items(): @@ -91,9 +97,10 @@ def item_not_found(self, item_type: str, item_name: str) -> None: class Controller: - def __init__(self, model_class, view_class) -> None: - self.model = model_class - self.view = view_class + """The Controller is the intermediary between the Model and the View.""" + def __init__(self, model_class: Model, view_class: View) -> None: + self.model: Model = model_class + self.view: View = view_class def show_items(self) -> None: items = list(self.model) @@ -106,22 +113,23 @@ def show_item_information(self, item_name: str) -> None: :param str item_name: the name of the {item_type} item to show information about """ try: - item_info = self.model.get(item_name) + item_info: str = self.model.get(item_name) except Exception: - item_type = self.model.item_type + item_type: str = self.model.item_type self.view.item_not_found(item_type, item_name) else: - item_type = self.model.item_type + item_type: str = self.model.item_type self.view.show_item_information(item_type, item_name, item_info) class Router: + """The Router is the entry point of the application.""" def __init__(self): self.routes = {} - def register(self, path: str, controller_class, model_class, view_class) -> None: - model_instance = model_class() - view_instance = view_class() + def register(self, path: str, controller_class: Controller, model_class: Model, view_class: View) -> None: + model_instance: Model = model_class() + view_instance: View = view_class() self.routes[path] = controller_class(model_instance, view_instance) def resolve(self, path: str) -> Controller: From 58bd201b48802dc0f69eafb083366d2fbf1824d6 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sat, 3 May 2025 23:52:57 +0200 Subject: [PATCH 09/16] Defined "random_animal" with random animal from list. --- patterns/creational/abstract_factory.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/patterns/creational/abstract_factory.py b/patterns/creational/abstract_factory.py index 0ec49bbf..51658f4e 100644 --- a/patterns/creational/abstract_factory.py +++ b/patterns/creational/abstract_factory.py @@ -90,6 +90,9 @@ def main() -> None: if __name__ == "__main__": + animals = ['dog', 'cat'] + random_animal = random.choice(animals) + shop = PetShop(random_animal) import doctest From a50bb549fedf403d0b18f6ba38e9cf5a7b62f903 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sun, 4 May 2025 02:08:23 +0200 Subject: [PATCH 10/16] - Moved AbstractExpert - Changed __init__ in AbstractExpert to abstract method - Added comments --- patterns/other/blackboard.py | 46 +++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/patterns/other/blackboard.py b/patterns/other/blackboard.py index cd2eb7ab..6eb7f82e 100644 --- a/patterns/other/blackboard.py +++ b/patterns/other/blackboard.py @@ -9,13 +9,27 @@ https://en.wikipedia.org/wiki/Blackboard_system """ -from __future__ import annotations - -import abc +from abc import ABC, abstractmethod import random +class AbstractExpert(ABC): + """Abstract class for experts in the blackboard system.""" + @abstractmethod + def __init__(self, blackboard: object) -> None: + self.blackboard = blackboard + + @property + @abstractmethod + def is_eager_to_contribute(self): + raise NotImplementedError("Must provide implementation in subclass.") + + @abstractmethod + def contribute(self): + raise NotImplementedError("Must provide implementation in subclass.") + class Blackboard: + """The blackboard system that holds the common state.""" def __init__(self) -> None: self.experts = [] self.common_state = { @@ -30,6 +44,7 @@ def add_expert(self, expert: AbstractExpert) -> None: class Controller: + """The controller that manages the blackboard system.""" def __init__(self, blackboard: Blackboard) -> None: self.blackboard = blackboard @@ -45,21 +60,11 @@ def run_loop(self): return self.blackboard.common_state["contributions"] -class AbstractExpert(metaclass=abc.ABCMeta): - def __init__(self, blackboard: Blackboard) -> None: - self.blackboard = blackboard - - @property - @abc.abstractmethod - def is_eager_to_contribute(self): - raise NotImplementedError("Must provide implementation in subclass.") - - @abc.abstractmethod - def contribute(self): - raise NotImplementedError("Must provide implementation in subclass.") - - class Student(AbstractExpert): + """Concrete class for a student expert.""" + def __init__(self, blackboard) -> None: + super().__init__(blackboard) + @property def is_eager_to_contribute(self) -> bool: return True @@ -72,6 +77,10 @@ def contribute(self) -> None: class Scientist(AbstractExpert): + """Concrete class for a scientist expert.""" + def __init__(self, blackboard) -> None: + super().__init__(blackboard) + @property def is_eager_to_contribute(self) -> int: return random.randint(0, 1) @@ -84,6 +93,9 @@ def contribute(self) -> None: class Professor(AbstractExpert): + def __init__(self, blackboard) -> None: + super().__init__(blackboard) + @property def is_eager_to_contribute(self) -> bool: return True if self.blackboard.common_state["problems"] > 100 else False From 9ad720667af7dd83e636da7eb48573d0d806154f Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sun, 4 May 2025 02:11:26 +0200 Subject: [PATCH 11/16] Removed object type from init --- patterns/other/blackboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patterns/other/blackboard.py b/patterns/other/blackboard.py index 6eb7f82e..3eea314a 100644 --- a/patterns/other/blackboard.py +++ b/patterns/other/blackboard.py @@ -15,7 +15,7 @@ class AbstractExpert(ABC): """Abstract class for experts in the blackboard system.""" @abstractmethod - def __init__(self, blackboard: object) -> None: + def __init__(self, blackboard) -> None: self.blackboard = blackboard @property From e8343854455ca2a00268571a31de7ea60931f029 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sun, 4 May 2025 02:21:47 +0200 Subject: [PATCH 12/16] Retry --- patterns/other/blackboard.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/patterns/other/blackboard.py b/patterns/other/blackboard.py index 3eea314a..970259d0 100644 --- a/patterns/other/blackboard.py +++ b/patterns/other/blackboard.py @@ -12,6 +12,7 @@ from abc import ABC, abstractmethod import random + class AbstractExpert(ABC): """Abstract class for experts in the blackboard system.""" @abstractmethod @@ -20,18 +21,18 @@ def __init__(self, blackboard) -> None: @property @abstractmethod - def is_eager_to_contribute(self): + def is_eager_to_contribute(self) -> bool: raise NotImplementedError("Must provide implementation in subclass.") @abstractmethod - def contribute(self): + def contribute(self) -> None: raise NotImplementedError("Must provide implementation in subclass.") class Blackboard: """The blackboard system that holds the common state.""" def __init__(self) -> None: - self.experts = [] + self.experts: list = [AbstractExpert] self.common_state = { "problems": 0, "suggestions": 0, @@ -138,7 +139,7 @@ def main(): if __name__ == "__main__": - random.seed(1234) # for deterministic doctest outputs + #random.seed(1234) # for deterministic doctest outputs import doctest doctest.testmod() From 8c0b293b4590f25bb864bcbfca16a696e8a8194a Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sun, 4 May 2025 02:34:47 +0200 Subject: [PATCH 13/16] Retry2 --- patterns/other/blackboard.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patterns/other/blackboard.py b/patterns/other/blackboard.py index 970259d0..e02246b9 100644 --- a/patterns/other/blackboard.py +++ b/patterns/other/blackboard.py @@ -21,7 +21,7 @@ def __init__(self, blackboard) -> None: @property @abstractmethod - def is_eager_to_contribute(self) -> bool: + def is_eager_to_contribute(self) -> int: raise NotImplementedError("Must provide implementation in subclass.") @abstractmethod @@ -32,7 +32,7 @@ def contribute(self) -> None: class Blackboard: """The blackboard system that holds the common state.""" def __init__(self) -> None: - self.experts: list = [AbstractExpert] + self.experts: list = [] self.common_state = { "problems": 0, "suggestions": 0, From 092fdd3837c408ad8fd32213e52cfe993ec0b44f Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sun, 4 May 2025 02:40:37 +0200 Subject: [PATCH 14/16] fix doctest --- patterns/other/blackboard.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/patterns/other/blackboard.py b/patterns/other/blackboard.py index e02246b9..df4b7697 100644 --- a/patterns/other/blackboard.py +++ b/patterns/other/blackboard.py @@ -121,13 +121,9 @@ def main(): >>> from pprint import pprint >>> pprint(contributions) ['Student', - 'Student', - 'Student', - 'Student', 'Scientist', 'Student', 'Student', - 'Student', 'Scientist', 'Student', 'Scientist', From 049d5559b32f21a1667485bb0115133b8a17f562 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sun, 4 May 2025 02:44:18 +0200 Subject: [PATCH 15/16] Retry3 --- patterns/other/blackboard.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/patterns/other/blackboard.py b/patterns/other/blackboard.py index df4b7697..a981dcc0 100644 --- a/patterns/other/blackboard.py +++ b/patterns/other/blackboard.py @@ -123,19 +123,12 @@ def main(): ['Student', 'Scientist', 'Student', - 'Student', - 'Scientist', - 'Student', - 'Scientist', - 'Student', - 'Student', - 'Scientist', - 'Professor'] + 'Student',] """ if __name__ == "__main__": - #random.seed(1234) # for deterministic doctest outputs + random.seed(1234) # for deterministic doctest outputs import doctest doctest.testmod() From 79a41c7e9710336c495bd015810689170ccbdcc4 Mon Sep 17 00:00:00 2001 From: Chris Dorsman <39407105+cdorsman@users.noreply.github.com> Date: Sun, 4 May 2025 02:47:38 +0200 Subject: [PATCH 16/16] Retry4 --- patterns/other/blackboard.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/patterns/other/blackboard.py b/patterns/other/blackboard.py index a981dcc0..58fbdb98 100644 --- a/patterns/other/blackboard.py +++ b/patterns/other/blackboard.py @@ -120,10 +120,13 @@ def main(): >>> from pprint import pprint >>> pprint(contributions) - ['Student', - 'Scientist', - 'Student', - 'Student',] + ['Student', + 'Scientist', + 'Student', + 'Scientist', + 'Student', + 'Scientist', + 'Professor'] """