Showing 27 of 27 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
def convert_messages(messages):
result = []
for message in messages:
role = convert_role(message["role"])
result.append({"role": role, "message": message["content"]})
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 72.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
def convert_messages(messages):
result = []
for message in messages:
role = convert_role(message["role"])
result.append({"role": role, "content": message["content"]})
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 72.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function convert_type
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def convert_type(x, memory={}):
if isinstance(x, t.Type):
return x
if x == int:
return t.int
- 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
Function make_examples
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def make_examples(func, tested_func):
def safe_eval(node_or_string):
"""Safely evaluate Python expressions from AST nodes or strings."""
try:
if isinstance(node_or_string, ast.AST):
- 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
Function check_args
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def check_args(self, args, kwargs, variables, variableMap):
for var, arg in zip(variables, args):
if var in kwargs:
raise ValueError(f"got multiple values for argument '{var}'")
variableMap[var] = arg
- 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
Function main
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def main(
Function use_llama
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def use_llama(
Function __init__
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, answer, answer_type, completion, reason, errors, messages):
Function defun
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def defun(
Function make_coding_prompt
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def make_coding_prompt(
Function query
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def query(
Function __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(
Function _check_input
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _check_input(variables, input):
if not isinstance(input, dict):
raise ValueError(f"Input must be a dictionary: {input}")
for variable in variables:
if variable not in input:
- 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
Function ask_and_parse
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def ask_and_parse(return_type, messages):
retry = False
errors = []
for _ in range(10):
- 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
Function get_packages
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def get_packages(source_code):
tree = ast.parse(source_code)
packages = []
for node in ast.walk(tree):
- 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. Open
return t.str
Avoid too many return
statements within this function. Open
return t.list(convert_type(args[0], memory))
Avoid too many return
statements within this function. Open
return t.tuple(*[convert_type(item_type, memory) for item_type in args])
Avoid too many return
statements within this function. Open
return t.literal(*get_args(x))
Avoid too many return
statements within this function. Open
return t.record(convert_type(args[0], memory), convert_type(args[1], memory))