327 self["blacklist"] = join(settings["CONF_DIR"], "blacklist.conf")
328 settings["blacklist"] = self["blacklist"]
329
330 def parseArgs(self, *action):331 """If an action was provided, store it for further processing."""
332 if len(action) == 1:
333 self["action"] = action[0]
215
216 super(MetricDatagramReceiver, cls).build(root_service)
217
218 def datagramReceived(self, data, addr):219 (host, _) = addr
220 if sys.version_info >= (3, 0):
221 data = data.decode('utf-8')
244 MetricReceiver.connectionMade(self)
245 self.unpickler = get_unpickler(insecure=settings.USE_INSECURE_UNPICKLER)
246
247 def stringReceived(self, data):248 try:
249 datapoints = self.unpickler.loads(data)
250 # Pickle can throw a wide range of exceptions
288 else:
289 log.query("%s connection lost: %s" % (self.peerAddr, reason.value))
290
291 def stringReceived(self, rawRequest):292 request = self.unpickler.loads(rawRequest)
293 cache = MetricCache()
294 if request['type'] == 'cache-query':
2
3
4class TestSettings(Settings):
5 def readFrom(*args, **kwargs):6 pass
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