File pylint_extensions.py
has 2337 lines of code (exceeds 250 allowed). Consider refactoring. Open
# coding: utf-8
#
# Copyright 2018 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Function check_docstring_section_indentation
has a Cognitive Complexity of 94 (exceeds 5 allowed). Consider refactoring. Open
def check_docstring_section_indentation(
self, node: astroid.nodes.FunctionDef
) -> None:
"""Checks whether the function argument definitions ("Args": section,
"Returns": section, "Yield": section, "Raises: section) are indented
- 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 process_tokens
has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring. Open
def process_tokens(self, tokens: List[tokenize.TokenInfo]) -> None:
"""Process tokens to check if there is a line break after the bracket.
Args:
tokens: List[TokenInfo]. Object to process tokens.
- 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_exceptional_type_is_documented
has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring. Open
def _check_exceptional_type_is_documented(
self,
type_status_dict: TypeStatusDict,
import_status_dict: Optional[ImportStatusDict],
token_type: 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 _process_module_tokens
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
def _process_module_tokens(
self, tokens: List[tokenize.TokenInfo], node: astroid.Module
) -> None:
"""Checks if the MyPy type ignores present in a module are properly
documented by a code comment or not. Also, checks for unnecessary code
- 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_typeinfo
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
def check_typeinfo(
self,
node: astroid.nodes.FunctionDef,
node_doc: _check_docs_utils.Docstring
) -> None:
- 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_comment_is_present_with_cast_method
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def check_comment_is_present_with_cast_method(
self, tokens: List[tokenize.TokenInfo], node: astroid.Module
) -> None:
"""Checks whether the cast method in a module has been documented
or not. If the cast method is not documented then adds an error
- 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_docstring_structure
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def check_docstring_structure(
self, node: astroid.NodeNG
) -> None:
"""Checks whether the docstring has the correct structure i.e.
do not have space at the beginning and have a period at the end of
- 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_arguments_in_docstring
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def check_arguments_in_docstring(
self,
doc: _check_docs_utils.Docstring,
arguments_node: astroid.nodes.Arguments,
warning_node: astroid.nodes.NodeNG,
- 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 process_tokens
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def process_tokens(self, tokens: List[tokenize.TokenInfo]) -> None:
"""Custom pylint checker to ensure that comments follow correct style.
Args:
tokens: list(TokenInfo). Object to access all tokens of a module.
- 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_newline_above_args
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def check_newline_above_args(
self,
node: astroid.nodes.FunctionDef,
docstring: List[str]
) -> None:
- 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 process_tokens
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def process_tokens(self, tokens: List[tokenize.TokenInfo]) -> None:
"""Custom pylint checker which allows paramas to disable a rule for a
single line only.
Args:
- 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 visit_call
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def visit_call(self, node: astroid.Call) -> None:
"""Visit a function call to ensure that the call is
not using any disallowed functions.
Args:
- 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_import_status
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def _check_import_status(
self,
import_status_dict: ImportStatusDict,
token_type: int,
token: str,
- 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_exceptional_type_is_documented
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def _check_exceptional_type_is_documented(
Avoid deeply nested control flow statements. Open
if re.search(r':$', stripped_line):
in_freeform_section = True
Avoid deeply nested control flow statements. Open
if current_line_indentation != (
args_indentation_in_spaces + 8):
self.add_message(
'8-space-indentation-in-docstring', node=node)
Avoid deeply nested control flow statements. Open
if re.search(r':$', stripped_line):
in_freeform_section = True
# Check for the start of an Args: section and check the correct
# indentation.
Function visit_return
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def visit_return(
self, node: astroid.nodes.FunctionDef
) -> None:
"""Visits a function node that contains a return statement and verifies
that the return value and the return type are documented.
- 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
if last_content_before_comment.endswith(
('(', '[', '{')
):
continue
self.add_message(
Avoid deeply nested control flow statements. Open
if bracket_count == 0:
position = char_num
bracket_count += 1
Avoid deeply nested control flow statements. Open
if (
error_code not in
self.config.allowed_type_ignore_error_codes
):
encountered_prohibited_error_codes.append(
Avoid deeply nested control flow statements. Open
if comment_index == 0:
continue
Avoid deeply nested control flow statements. Open
if current_line_indentation != (
args_indentation_in_spaces + 4):
self.add_message(
'4-space-indentation-in-docstring', node=node)
in_description = True
Avoid deeply nested control flow statements. Open
if (split_line[comment_index - 1].endswith(':') or
split_line[comment_index - 1].endswith('):')):
excluded = False
elif line.endswith(':') or line.endswith('):'):
Avoid deeply nested control flow statements. Open
if (
current_line_indentation !=
args_indentation_in_spaces + 4 and
not in_freeform_section
):
Function visit_raise
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def visit_raise(
self, node: astroid.nodes.FunctionDef
) -> None:
"""Visits a function node that raises an exception and verifies that all
exceptions raised in the function definition are documented.
- 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
if current_line_indentation != (
args_indentation_in_spaces + 4):
self.add_message(
'4-space-indentation-in-docstring', node=node)
Consider simplifying this complex logical expression. Open
if stripped_line.startswith('Returns:'):
current_docstring_section = self.DOCSTRING_SECTION_RETURNS
in_freeform_section = False
in_description = False
args_indentation_in_spaces = current_line_indentation
Function visit_importfrom
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def visit_importfrom(self, node: astroid.Import) -> None:
"""Visits all import-from statements in a python file and checks that
modules are imported. It then adds a message accordingly.
Args:
- 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 open
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def open(self) -> None:
"""Parse the forbidden imports."""
module_to_forbidden_imports: List[Tuple[str, str]] = [
forbidden_import.strip().split(':')
for forbidden_import in self.config.forbidden_imports
- 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 _iterate_forbidden_imports
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _iterate_forbidden_imports(
self, node: astroid.nodes.Import
) -> Generator[Tuple[str, Tuple[str, Optional[str]]], None, None]:
"""Yields pairs of module name and forbidden imports.
- 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 process_tokens
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def process_tokens(self, tokens: List[tokenize.TokenInfo]) -> None:
"""Custom pylint checker which makes sure that every keyword is
followed by a single space.
Args:
- 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 visit_classdef
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def visit_classdef(self, node: astroid.nodes.ClassDef) -> None:
"""Visit each class definition in a module and check if there is a
single new line below each class docstring.
Args:
- 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_comment_is_present_with_any_type
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def check_comment_is_present_with_any_type(
self, tokens: List[tokenize.TokenInfo], node: astroid.Module
) -> None:
"""Checks whether the Any type in a module has been documented
or not. If the Any type is not documented then adds an error
- 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 visit_compare
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def visit_compare(self, node: astroid.Compare) -> None:
"""Called for comparisons (a != b).
Args:
node: astroid.Compare. A node indicating comparison.
- 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 visit_module
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def visit_module(self, node: astroid.Module) -> None:
"""Visit a module to ensure that there is a blank line below
file overview docstring.
Args:
- 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_comment_is_present_with_object_class
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def check_comment_is_present_with_object_class(
self, tokens: List[tokenize.TokenInfo], node: astroid.Module
) -> None:
"""Checks whether the object class in a module has been documented
or not. If the object class is not documented then adds an error
- 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 visit_classdef
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def visit_classdef(self, node: astroid.nodes.ClassDef) -> None:
"""Visit each class definition in controllers layer module and check
if it contains schema or not.
Args:
- 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 visit_import
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def visit_import(self, node: astroid.nodes.Import) -> None:
"""Visits every import statement in the file.
Args:
node: astroid.node_classes.Import. Node for a import statement
- 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"