All Questions
21 questions
0
votes
1
answer
127
views
Correct way to deduplicate conditional statements [closed]
I'm facing with problem that in every function (with serves as service for endpoint) I need to check what is value of query parameter (mode). I need to check it on many callables, E.g.
def create(self,...
1
vote
2
answers
196
views
Should I add functionality by adding a new method to a class - or should I "register" the new functionality into a data structure?
I have one large class that computes ~50 different metrics (each metric has no side effects).
My code is similar to this:
class ReportingMetrics:
def __init__(self, data:pd.DataFrame, config:dict)...
1
vote
1
answer
38
views
Register a collection of tested object and get one configuraton out of it
I have a yml configuration file that list multiple application. Each application can contain multiple configuration. And of course each configuration can contain multiple mode
apps:
- name: foo
...
1
vote
1
answer
4k
views
Using isinstance() during exception handling for subsequent action
I've read various posts that polymorphism should be used instead of isinstance, and I agree that makes sense when the use of isinstance is checking the subtypes of a class to determine what to do. ...
-1
votes
1
answer
164
views
How would you design the abstraction/class(es)/component(s) of a third-party service/api used in your application?
Lets say you were designing a Twitter client for people with people could see tweets and post tweets? How would you design the twitter api abstraction? Many of the api wrappers I've seen feature an ...
2
votes
0
answers
69
views
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 ...
0
votes
1
answer
63
views
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,...
1
vote
2
answers
101
views
__init__ arguments differ from object attributes
Is the following class definition a good design?
class Myclass:
def __init__(self,num1,num2):
self.complicated_tree = __class__.object_creator(num1,num2)
@classmethod
def ...
4
votes
1
answer
2k
views
Python class naming: nested classes or composed names?
I encountered a scenario where I cannot decide on which is the best (or worst) naming strategy. The context is the following: a bracket (as in a tournament) made up of nodes, where is node is made up ...
1
vote
3
answers
2k
views
Is isinstance a good way of identifying the type of an object?
I have a bunch of classes inheriting from Violation. These subclasses model violations to different rules: UsedTimeslot, TeamConstraint, etc...
I need to check what kind of violation happened in ...
0
votes
1
answer
71
views
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 ...
0
votes
1
answer
48
views
Categories with fixed choices design
I need to make a category/type class to identify an object. The usual way to do it is just pass a string to initialize a new category:
category = Category('A')
obj = Object(category)
However, the set ...
2
votes
1
answer
96
views
Scheduling rule violation design
In the context of sports scheduling, a scheduling rule violation (let's call it simply violation from now on) is produced when trying to allocate a match in an illegal timeslot. There is a wide ...
7
votes
2
answers
3k
views
self vs super() "inconsistency" in Python
According to Python documentation, super() can be used without arguments inside class definitions, because the compiler implicitly feeds it with contextual arguments:
class C(B):
def method(self, ...
8
votes
3
answers
2k
views
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):
...