All Questions
23 questions
2votes
1answer
131views
A Design Pattern for a component which both writes to and reads from an ordered event log
I am searching for a good design for a set of components I am writing for a system. I believe it is very likely there is a Design Pattern, or set of Design Patterns, which could be combined to solve ...
0votes
1answer
239views
How do we nest decorators?
It is possible to nest many decorators. @decorator_one @decorator_two @decorator_three @decorator_four def some_silly_function(): pass How do we write a decorator class so that the order in which ...
1vote
1answer
314views
Where to create repository instances?
I've several repositories. To make them testable, I add the ORM session in the constructor. class Repository: def __init__(session): self.session = session def save(object): self.session()...
0votes
0answers
86views
Download method of type void vs response
Given a method that is widely used and has a void return type: from somepackage import download_model from somepackage import get_filename def download(name, download_path): response = ...
-2votes
2answers
1kviews
Best practice: keep DB models in one file or split into modules?
I've a Python project with ~30 SQLAlchemy models and I'm not sure where they belong. All models belong to the DB but also to a module, so I'm not sure about the right namespace. Here are some ideas: ...
1vote
2answers
90views
Building a plugins-based code in Python
I have a program which perform different actions depending on the plugins that are passed. For example, python main.py -m foo -m bar will perform the actions of foo and bar. The structure of the ...
0votes
1answer
207views
Passing messages through a chain of containers in python
When I write python code for simulations, I often end up with the following situation: I have a class describing the general environment which contains a list of instances of a class that describes ...
9votes
3answers
6kviews
Better conditional debugging pattern?
Given the need to log only in debug mode the easiest way would be to use if conditions: def test(x, debug=False): if debug: print(x) # ...Some more code if debug: print("...
2votes
0answers
69views
How to interface with very badly written code in Python? [duplicate]
I have to extend some very badly written Python code (no documentation, very interdependent, barely any encapsulation, very static, everything hard-coded, etc..) and therefore do I obviously have to ...
0votes
1answer
63views
Method grouping other methods of the same family and how to call any of these separately
Worse title ever but I don't really know how to describe my scenario in a line... So I have a method that wraps the calls of a many methods of the same nature. Once any of these methods have finished,...
0votes
1answer
71views
Redesign factory to throw error on load time instead of on execution time
I am using a factory pattern to get objects that shouldn't be instantiated other than the factory class. These objects are of type ViolationType, which represent violations on a set of rule. Here is ...
1vote
2answers
157views
Critique on design principle and validity of such in general
I was hoping you could give some feedback on an idea I had for designing functions. I am trying to think of a unifying principle for choosing what functions should return. The specific project is ...
8votes
3answers
2kviews
Refactoring of a client API for avoid duplicated code and unclear passage of parameters
I need to develop an API, the functions of the API are requests that call the service exposed by a server. Initially the API worked like this: class Server: def firstRequest(self, arg1, arg2): ...
8votes
2answers
4kviews
how to refactor many singletons
I have a medium-sized python program (~5000 lines of code), which I've built up over time, with no particular plan as I went ahead. The architecture I've ended up with consists of 5-6 large Singleton ...
2votes
1answer
438views
Python Classes and Design Questions
What is the best way to design a class to see if an update occurs on a property? I have a whole bunch of classes, and current am going through a re-design of the python package I created. ...