sourcery_analytics.metrics.utils

Utility “metrics” for use in analysis.

sourcery_analytics.metrics.utils.method_qualname(method: FunctionDef) str

Returns the fully-qualified name of the method.

If the method was constructed from an object astroid recognizes as a module, this will look something like "module.method", but astroid will fall back to the full file path if it can’t be sure.

Examples

>>> method = astroid.extract_node("def foo(): pass", module_name="bar")
>>> method_qualname(method)
'bar.foo'
sourcery_analytics.metrics.utils.method_name(method: FunctionDef) str

Returns the name of the method.

Not very useful by itself, but can be combined with other metrics for convenience.

Examples

>>> method_name("def foo(): pass")
'foo'
sourcery_analytics.metrics.utils.method_lineno(method: FunctionDef) int

Returns the line number of the method.

Not very useful by itself, but can be combined with other metrics for convenience.

Examples

>>> method_lineno("def foo(): pass")
1
sourcery_analytics.metrics.utils.method_file(method: FunctionDef) str

Returns the file name the method is in.

Not very useful by itself, but can be combined with other metrics for convenience.

Examples

Inline code doesn’t have a file. >>> method_file(“def foo(): pass”) ‘<?>’

sourcery_analytics.metrics.utils.node_type_name(node: NodeNG) str

Returns a string representing the type of the node.

Useful for breakdowns of an AST by node type.

Examples

>>> source = '''
...     def x(y, z):  #@
...         x = y + z  #@
... '''
>>> nodes = astroid.extract_node(source)
>>> node_type_name(nodes[0])
'FunctionDef'
>>> node_type_name(nodes[1])
'Assign'