Jun-29-2021, 05:03 PM
(This post was last modified: Jun-29-2021, 06:07 PM by gserranowong.)
First of all, I realize inheritance and Unions are totally two different things. However, I would like to get your opinions on this issue I detail below:
Let's say we have this class.
This Context depends on the value of config_type meaning the context is dependent on its value. Which implementation of Context is best?
or
To be more specific. Let say you have a configuration class, this configuration will hold data that will be used to configure a process. This process will contain a few things that relate to all configurations, like retries value. However, it is expected that based on config_type there is an additional context that is required. This is highly related to the particular configuration type. Note that these classes only hold data and they are not expected to implement any behaviors in the future. However, it is expected that the SomeEnum enumeration will be extended and more "contexts" will be added at some point. Think of my config as immutable.
Let's say we have this class.
1 2 3 4 |
class MyConfig(): config_type : SomeEnum retries: int context: Context |
1 2 3 4 5 6 7 8 9 |
class MySpecificContext: value: int name: str class OtherUnrelatedContext: length: int position: int Contex = Union[MySpecificContex,OtherUnrelatedContext] |
1 2 3 4 5 6 7 8 9 10 |
class Context: pass class MySpecificContext(Context): value: int name: str class OtherUnrelatedContext(Context): length: int position: int |