Function create_failure_handler
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def create_failure_handler(self, handlers_config: dict) -> Callable:
def failure_handler(context: Any) -> None:
for handler_definition in handlers_config:
if handler_definition["type"] == "slack":
connection = BaseHook.get_connection(handler_definition["connection_id"])
- 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
Too few public methods (1/2) Open
class NotificationHandlersFactory:
- Read upRead up
- Exclude checks
Used when class has too few public methods, so be sure it's really worth it.
Method could be a function Open
def create_failure_handler(self, handlers_config: dict) -> Callable:
- Read upRead up
- Exclude checks
Used when a method doesn't use its bound instance, and so could be written as a function.
Either all return statements in a function should return an expression, or none of them should. Open
def failure_handler(context: Any) -> None:
- Read upRead up
- Exclude checks
According to PEP8, if any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None, and an explicit return statement should be present at the end of the function (if reachable)
Unnecessary elif
after return
Open
if handler_definition["type"] == "slack":
- Read upRead up
- Exclude checks
Used in order to highlight an unnecessary block of code following an if containing a return statement. As such, it will warn when it encounters an else following a chain of ifs, all of them containing a return statement.
Imports from package dbt_airflow_factory are not grouped Open
from dbt_airflow_factory.notifications.ms_teams_webhook_operator import (
- Read upRead up
- Exclude checks
Used when imports are not grouped by packages
Import from dbt_airflow_factory.notifications.ms_teams_webhook_operator import MSTeamsWebhookOperator
should be placed at the top of the module Open
from dbt_airflow_factory.notifications.ms_teams_webhook_operator import (
- Read upRead up
- Exclude checks
Used when code and imports are mixed
Missing class docstring Open
class NotificationHandlersFactory:
- Read upRead up
- Exclude checks
Used when a class has no docstring.Even an empty class must have a docstring.
Missing module docstring Open
from collections.abc import Callable
- Read upRead up
- Exclude checks
Used when a module has no docstring.Empty modules do not require a docstring.
Missing function or method docstring Open
def create_failure_handler(self, handlers_config: dict) -> Callable:
- Read upRead up
- Exclude checks
Used when a function or method has no docstring.Some special methods like init do not require a docstring.