IlyaGusev/rulm

View on GitHub
self_instruct/src/data_processing/generate_char_chats.py

Summary

Maintainability
C
1 day
Test Coverage

Function main has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

def main(
    chars_path,
    output_path,
    template_path,
    request_batch_size=4
Severity: Minor
Found in self_instruct/src/data_processing/generate_char_chats.py - About 4 hrs to fix

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

Function parse_chat has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

def parse_chat(result):
    try:
        chat = json.loads(result)
    except Exception:
        print("Incorrect JSON:", result)
Severity: Minor
Found in self_instruct/src/data_processing/generate_char_chats.py - About 1 hr to fix

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

Function fix_output_records has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def fix_output_records(records):
    for char in records:
        unique_dialogues = dict()
        topics = char["topics"]
        if "dialogues" in char:
Severity: Minor
Found in self_instruct/src/data_processing/generate_char_chats.py - About 1 hr to fix

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

                    for dialogue in record["dialogues"]:
                        topic = dialogue["topic"]
                        existing_keys.add(get_dialogue_key(record, topic))
            output_records = {get_char_key(char): char for char in output_records}
Severity: Major
Found in self_instruct/src/data_processing/generate_char_chats.py - About 45 mins to fix

    Avoid too many return statements within this function.
    Open

                return None
    Severity: Major
    Found in self_instruct/src/data_processing/generate_char_chats.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return None
      Severity: Major
      Found in self_instruct/src/data_processing/generate_char_chats.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return None
        Severity: Major
        Found in self_instruct/src/data_processing/generate_char_chats.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return chat
          Severity: Major
          Found in self_instruct/src/data_processing/generate_char_chats.py - About 30 mins to fix

            There are no issues that match your filters.

            Category
            Status