101 List Tickets based on different params
102 """
103
104 def before_get(self, args, view_kwargs):105 """
106 before get method to get the resource id for assigning schema
107 :param args:
193 Ticket Resource
194 """
195
196 def before_get(self, args, view_kwargs):197 """
198 before get method to get the resource id for assigning schema
199 :param args:
The parameters in the overridden method don't match the method defined in the parent class. There are three possible scenarios for this:
- The number of parameters are different in both methods
- One or more names of the parameters are different in both methods
- The order of parameters is different in both methods
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.
Bad practice
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
Recommended
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