CodeQL documentation

Signature mismatch in overriding method

ID: py/inheritance/signature-mismatch
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - quality
   - reliability
   - correctness
Query suites:
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

There are one (or more) legal parameters for an overridden method that are not legal for an overriding method. This will cause an error when the overriding method is called with a number of parameters that is legal for the overridden method. This violates the Liskov substitution principle.

Recommendation

Ensure that the overriding method accepts all the parameters that are legal for overridden method.

Example

In this example there is a mismatch between the legal parameters for the base class method (self, source, filename, symbol) and the extension method (self, source). The extension method can be used to override the base method as long as values are not specified for the filename and symbol parameters. If the extension method was passed the additional parameters accepted by the base method then an error would occur.


# Base class method
def runsource(self, source, filename="<input>", symbol="single"):
    ... # Definition
    
    
# Extend base class method
def runsource(self, source):
    ... # Definition

The extension method should be updated to support the filename and symbol parameters supported by the overridden method.

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy