Skip to main content

All Questions

0votes
1answer
127views

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,...
rozumir's user avatar
1vote
2answers
196views

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)...
MYK's user avatar
  • 343
1vote
1answer
38views

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 ...
CyDevos's user avatar
1vote
1answer
4kviews

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. ...
pstatix's user avatar
  • 1,047
-1votes
1answer
164views

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 ...
an_aspiring_engineer's user avatar
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 ...
PPP's user avatar
  • 29
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,...
dabadaba's user avatar
1vote
2answers
101views

__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 ...
l7ll7's user avatar
4votes
1answer
2kviews

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 ...
dabadaba's user avatar
1vote
3answers
2kviews

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 ...
dabadaba's user avatar
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 ...
dabadaba's user avatar
0votes
1answer
48views

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 ...
dabadaba's user avatar
2votes
1answer
96views

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 ...
dabadaba's user avatar
7votes
2answers
3kviews

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, ...
Alexey's user avatar
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): ...
k4ppa's user avatar

153050per page
close