suitcase/protocol.py
Function _create_packet_generator
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
Open
def _create_packet_generator(self):
while True:
curmsg = self.message_schema()
for i, (_name, field) in enumerate(curmsg):
bytes_required = field.bytes_required
- 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 deeply nested control flow statements. Open
Open
if len(self._available_bytes) < bytes_required:
yield None
continue
Avoid deeply nested control flow statements. Open
Open
if idx == -1: # no match in buffer
# Since we know the entire magic_seq is not here, there can be at most
# bytes_required - 1 bytes of the magic_seq available. Thus we keep
# that many bytes around in case it is the start of the magic field.
self._available_bytes = self._available_bytes[-(bytes_required - 1):]
Function feed
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def feed(self, new_bytes):
"""Feed a new set of bytes into the protocol handler
These bytes will be immediately fed into the parsing state machine and
if new packets are found, the ``packet_callback`` will be executed
- 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"