Function score
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Wontfix
def score(self, query: tp.GrayImage, draw: bool = False, scope: tp.Scope = None, only_score: bool = False) -> Optional(Tuple[tp.Scope, tp.Score]):
""" scoring of image matching """
try:
# if feature points is empty
if self.des is None:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Wontfix
return rect, (good_matches_rate, good_area_rate, hash, ssim)
Avoid too many return
statements within this function. Wontfix
return None
Avoid too many return
statements within this function. Wontfix
return None
Avoid too many return
statements within this function. Wontfix
return None
Avoid too many return
statements within this function. Open
return (good_matches_rate, good_area_rate, hash, ssim)
Refactor this function to reduce its Cognitive Complexity from 30 to the 15 allowed. Open
def score(self, query: tp.GrayImage, draw: bool = False, scope: tp.Scope = None, only_score: bool = False) -> Optional(Tuple[tp.Scope, tp.Score]):
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Rename function "getHash" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Wontfix
def getHash(data: list[float]) -> tp.Hash:
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...
Rename function "aHash" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Wontfix
def aHash(img1: tp.GrayImage, img2: tp.GrayImage) -> int:
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...
Rename function "hammingDistance" to match the regular expression ^[a-z_][a-z0-9_]{2,}$. Wontfix
def hammingDistance(hash1: tp.Hash, hash2: tp.Hash) -> int:
- Read upRead up
- Exclude checks
Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.
Noncompliant Code Example
With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$
def MyFunction(a,b): ...
Compliant Solution
def my_function(a,b): ...