97 def __str__(self):
98 return self.semester_code
99
100 def save(self, *args, **kwargs):101 # try:
102 # deg = Degree.objects.get(degree_short=self.degree_short)
103 # if deg:
513 # return self.offeredcourses.get().student.uid + "_" + self.course.course_name + "_" + self.status
514 return self.section + "_" + self.course.course_name + "_" + self.status
515
516 def save(self, *args, **kwargs):517
518 print(self.section)
519 print(self.course.course_code)
21 help='Use Pre-defined Defaults. useful for seeing how the project works without customization.'
22 )
23
24 def handle(self, **options):25 init(autoreset=True)
26 use_default_settings = options['default']
27 interactive = not use_default_settings
99 students = models.ManyToManyField('student_portal.Student')
100 limit = models.SmallIntegerField(default=40, blank=True, null=True)
101
102 def save(self, *args, **kwargs):103 print(self.batch, self.section, self.sec_batch)
104 if self.sec_batch is None or self.batch + "-" + self.section != str(self.sec_batch):
105 self.sec_batch = str(self.batch) + "-" + str(self.section)
2from initial.models import Student,User
3
4class Command(BaseCommand):
5 def handle(self, **options): 6 # u = User(first_name = "saya",last_name = "dapra",email= "[email protected]",password = 'redragon')
7 # u.save()
8 # print(u)
The parameters in the overridden method don't match the method defined in the parent class. There are three possible scenarios for this:
Python will allow this, but if the overridden method is intended to be executed from external code, you may want to reconsider this. Overriding a method without ensuring that both methods accept the same name, number, and order of parameters has the potential to cause an error when the overriding method is called with parameters that is illegal for the overridden method. This violates the Liskov substitution principle.
class Base:
def summation(cycle, x, y, z):
log(cycle)
return x + y + z
class UneqalArgLen(Base):
def summation(cycle, x, y):
log(cycle)
return x + y
class RenamedArg(Base):
def summation(cycle, x, y, zee=None):
log(cycle)
return x + y
class unorderdArgs(Base):
def summation(x, cycle, y, z):
log(cycle)
return x + y + z
There can be multiple approaches to address this inconsistency. The first approach is to re-think the method signature in the parent class itself if the child classes are expected to implement a variable number of arguments in their own implementation. If the exploitation here is a special case, this can be dealt with making it compatible with the parent's class method signature, like this:
class Base:
def summation(cycle, x, y, z):
log(cycle)
return x + y + z
class FixedUneqalArgLen(Base):
def summation(cycle, x, y, z=None):
log(cycle)
return x + y
class NoRenamedArg(Base):
def summation(cycle, x, y, _): # using `_` won't trigger the issue.
log(cycle)
return x + y
class NounorderdArgs(Base):
def summation(cycle, x, y, z): # No surprises here
log(cycle)
return x + y + z