0

I have written this code and code climate shows: Function _filter_empty_entities has a Cognitive Complexity of 7 (exceeds 5 allowed)

def _filter_empty_entities(payload):
    attrs = list(iter_entity_attrs(payload))
    Flag = False
    for j in attrs:
        if isinstance(value, int) and value is not None:
            Flag = True
        elif value:
            Flag = True
   if Flag:
       return payload
   else:
       return None

Any help?Thanks

damini chopra
  • 133
  • 2
  • 12

1 Answers1

0

Cognitive complexity is a:

measure of how difficult a unit of code is to intuitively understand

Pretty much Code Climate thinks the code is difficult to understand and test.

Try breaking down your function into smaller parts and examine the logic for where there maybe redundancy. Examine when you break your logic flow (for ex. addin in nested if, elsif).

Christine
  • 84
  • 6