inheritance

force implementing specific attributes in subclass python

扶醉桌前 提交于 2021-01-07 03:41:27
问题 I'm have a parent class, and I would like to "force" everyone that will inherit from it to implement some specific class attributes. I don't have this problem with methods, since I have created a dummy method that raises NotImplementedError , which makes it very clear. As for class attributes- I do not want to create them in the parent class and set them to None since that doesn't force the developer to implement them in the child class. A little code to demonstrate the current situation:

Extension methods for two different classes

旧时模样 提交于 2021-01-07 01:19:48
问题 I have a situation where in C# I consume data via an OData API. Actually, there are two different OData endpoints (two different models), where one is a superset of the other. I have created two different C# projects (A and B) which contain code to interact with the two API's. The code is automatically generated using Unchase OData Connected Service extension. As a result, project A and project B both contain a class ODataService , which is the main type to interact with. Depending on whether

Extension methods for two different classes

爷,独闯天下 提交于 2021-01-07 01:14:27
问题 I have a situation where in C# I consume data via an OData API. Actually, there are two different OData endpoints (two different models), where one is a superset of the other. I have created two different C# projects (A and B) which contain code to interact with the two API's. The code is automatically generated using Unchase OData Connected Service extension. As a result, project A and project B both contain a class ODataService , which is the main type to interact with. Depending on whether

models.E006 in abstract parent model - Django 3.1

梦想的初衷 提交于 2021-01-05 11:23:27
问题 I have an abstract model and a few other classes that inherit from it. # models.py class Parameter(models.Model): data = integer = models.IntegerField(blank=True, null=True) class Meta: abstract = True class Temperature(Parameter): received_timestamp = models.DateTimeField(default=datetime.now, blank=True) class Ph(Parameter): received_timestamp = models.DateTimeField(default=datetime.now, blank=True) although my Parameter class is abstract, I get models.E006 error in python manage.py

Stored variable of Self type (especially when subclassing)

随声附和 提交于 2021-01-02 12:57:35
问题 class LinkedNode<T> { var value: T var next: Self? required init(_ value: T) { self.value = value } } class DoublyNode<T>: LinkedNode<T> { weak var previous: DoublyNode? override var next: Self? { didSet { next.previous = self } } } I wish it compiles like this. But it doesn't. Stored property cannot have covariant 'Self' type I have to rewrite the code to make it compile and work: class LinkedNode<T> { var value: T var next: LinkedNode? required init(_ value: T) { self.value = value } }

Stored variable of Self type (especially when subclassing)

怎甘沉沦 提交于 2021-01-02 12:55:58
问题 class LinkedNode<T> { var value: T var next: Self? required init(_ value: T) { self.value = value } } class DoublyNode<T>: LinkedNode<T> { weak var previous: DoublyNode? override var next: Self? { didSet { next.previous = self } } } I wish it compiles like this. But it doesn't. Stored property cannot have covariant 'Self' type I have to rewrite the code to make it compile and work: class LinkedNode<T> { var value: T var next: LinkedNode? required init(_ value: T) { self.value = value } }

Stored variable of Self type (especially when subclassing)

谁说我不能喝 提交于 2021-01-02 12:55:46
问题 class LinkedNode<T> { var value: T var next: Self? required init(_ value: T) { self.value = value } } class DoublyNode<T>: LinkedNode<T> { weak var previous: DoublyNode? override var next: Self? { didSet { next.previous = self } } } I wish it compiles like this. But it doesn't. Stored property cannot have covariant 'Self' type I have to rewrite the code to make it compile and work: class LinkedNode<T> { var value: T var next: LinkedNode? required init(_ value: T) { self.value = value } }

Stored variable of Self type (especially when subclassing)

喜欢而已 提交于 2021-01-02 12:53:53
问题 class LinkedNode<T> { var value: T var next: Self? required init(_ value: T) { self.value = value } } class DoublyNode<T>: LinkedNode<T> { weak var previous: DoublyNode? override var next: Self? { didSet { next.previous = self } } } I wish it compiles like this. But it doesn't. Stored property cannot have covariant 'Self' type I have to rewrite the code to make it compile and work: class LinkedNode<T> { var value: T var next: LinkedNode? required init(_ value: T) { self.value = value } }

MVC exclude controller usage

拈花ヽ惹草 提交于 2021-01-01 04:43:16
问题 I have created a 'template' project A which has 10 controllers ( partial class ). All these controllers are packed in a nuget package and are consumed by projects B, C & D. The nuget generates the controllers in the folder controllers/_core so they are nicely stored separately. The nuget package does not have a reference to the dll of project A. Now to get down to the problem; It could be that one of the controllers that are generated need to be modified. By adding a second partial we could

MVC exclude controller usage

久未见 提交于 2021-01-01 04:41:59
问题 I have created a 'template' project A which has 10 controllers ( partial class ). All these controllers are packed in a nuget package and are consumed by projects B, C & D. The nuget generates the controllers in the folder controllers/_core so they are nicely stored separately. The nuget package does not have a reference to the dll of project A. Now to get down to the problem; It could be that one of the controllers that are generated need to be modified. By adding a second partial we could