sourcery_analytics.metrics.method_length

Method length calculations.

The length of a method is a simple heuristic for assessing its complexity. In general, longer methods can be broken up into smaller ones to simplify the code.

Note that for obvious reasons, the method length is only defined for methods.

sourcery_analytics.metrics.method_length.method_length(method: FunctionDef) int

Calculates the method length as the number of statements in the method.

Parameters

method – a node for a function definition

Examples

>>> method_length("def add(x, y): z = x + y; return z")
2
sourcery_analytics.metrics.method_length.total_statement_count(node: NodeNG) int

Calculates the total number of statements in the node.

Parameters

node – any astroid node

Examples

>>> total_statement_count("if x: y()")
2
sourcery_analytics.metrics.method_length.statement_count(node: NodeNG) int

Count 1 for a statement and 0 otherwise.

Function and class definitions are skipped.