Showing 31 of 31 total issues
Post
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class Post:
_body = ""
_body_is_summary = False
_is_answer = False
_owner_rep = 1
- Create a ticketCreate a ticket
Cyclomatic complexity is too high in method populate. (12) Open
@staticmethod
def populate(current_version=None):
migrations_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../bin/migrations'))
existing_names = [x.migration_file for x in SESSION.query(SchemaMigration).all()]
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Cyclomatic Complexity
Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.
Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:
Construct | Effect on CC | Reasoning |
---|---|---|
if | +1 | An if statement is a single decision. |
elif | +1 | The elif statement adds another decision. |
else | +0 | The else statement does not cause a new decision. The decision is at the if. |
for | +1 | There is a decision at the start of the loop. |
while | +1 | There is a decision at the while statement. |
except | +1 | Each except branch adds a new conditional path of execution. |
finally | +0 | The finally block is unconditionally executed. |
with | +1 | The with statement roughly corresponds to a try/except block (see PEP 343 for details). |
assert | +1 | The assert statement internally roughly equals a conditional statement. |
Comprehension | +1 | A list/set/dict comprehension of generator expression is equivalent to a for loop. |
Boolean Operator | +1 | Every boolean operator (and, or) adds a decision point. |
Function command
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def command(*type_signature, reply=False, whole_msg=False, aliases=None):
if aliases is None:
aliases = []
# noinspection PyMissingTypeHints
- Read upRead up
- Create a ticketCreate a ticket
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 dispatch_command
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def dispatch_command(msg) -> str:
command_parts = msg.content.split(" ", 1)
if len(command_parts) == 2:
cmd, args = command_parts
- Read upRead up
- Create a ticketCreate a ticket
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_api_post
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def _parse_api_post(self, response: dict) -> None:
if "title" not in response or "body" not in response:
return
self._title = html.unescape(response["title"])
- Read upRead up
- Create a ticketCreate a ticket
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 _process_element_mapping
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def _process_element_mapping(self, element_map: dict, data: dict, is_api_response: bool = False):
# Take the API response map, and start setting the elements (and sub-elements, where applicable)
# to the attributes and variables in the object.
for (element, varmap) in element_map.items():
try:
- Read upRead up
- Create a ticketCreate a ticket
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 tell_rooms
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def tell_rooms(msg, has, hasnt, **kwargs):
global _rooms
target_rooms = set()
- Read upRead up
- Create a ticketCreate a ticket
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 spam_check
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def spam_check(name="Missingno.", all=False, sites=set(), max_rep=10, max_score=1):
def decorator(func):
def check(post):
if post.owner_rep <= max_rep and post.post_score <= max_score and all == (post.post_site not in sites):
reason = func(post)
- Read upRead up
- Create a ticketCreate a ticket
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 handle_pull
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def handle_pull():
porcelain.pull(_repo, remote_location=config.github + ".git")
for name in list(sys.modules.keys()):
if name not in DONT_RELOAD:
- Read upRead up
- Create a ticketCreate a ticket
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_room_config
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def parse_room_config():
with open("../config/rooms.json", "r") as room_config:
room_dict = json.load(room_config)
rooms = {}
- Read upRead up
- Create a ticketCreate a ticket
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 dispatch_shorthand_command
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def dispatch_shorthand_command(msg, room) -> str:
commands = msg.content[len(config.shorthand_prefix):].split()
output = []
processed_commands = []
- Read upRead up
- Create a ticketCreate a ticket
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 regex_spam_check
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def regex_spam_check(re, name="Missingno.", all=False, sites=set(), max_rep=10, max_score=1, **types):
compiled_regex = regex.compile(re)
@spam_check(name=name, all=all, sites=sites, max_rep=max_rep, max_score=max_score)
def check(post):
- Read upRead up
- Create a ticketCreate a ticket
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 regex_spam_check
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def regex_spam_check(re, name="Missingno.", all=False, sites=set(), max_rep=10, max_score=1, **types):
- Create a ticketCreate a ticket
Function init
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def init():
global _clients
global _init
global _room_permissions
global _rooms
- Read upRead up
- Create a ticketCreate a ticket
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 on_msg
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def on_msg(msg, client, room):
if isinstance(msg, events.MessagePosted) or isinstance(msg, events.MessageEdited):
message = msg.message
if message.owner.id in config.my_ids:
- Read upRead up
- Create a ticketCreate a ticket
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
if perm not in rooms:
rooms[perm] = set()
- Create a ticketCreate a ticket
Function spam_check
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def spam_check(name="Missingno.", all=False, sites=set(), max_rep=10, max_score=1):
- Create a ticketCreate a ticket
Function populate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def populate(current_version=None):
migrations_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../bin/migrations'))
existing_names = [x.migration_file for x in SESSION.query(SchemaMigration).all()]
new_files = sorted([os.path.basename(x) for x in os.listdir(migrations_path)
- Read upRead up
- Create a ticketCreate a ticket
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 __init__
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def __init__(self, json_data: str = None, api_response: dict = None, parent: Any = None) -> None:
if parent is not None:
if not isinstance(parent, Post):
raise TypeError("Parent object for a Post object must also be a Post object.")
else:
- Read upRead up
- Create a ticketCreate a ticket
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 "Too many arguments."
- Create a ticketCreate a ticket