Metrics

stats() (and PyReprism.stats()) return a CodeStats with line- and token-level metrics, suitable for building code datasets.

Code metrics produced by BaseLanguage.stats().

class PyReprism.metrics.CodeStats(lines: int, code_lines: int, comment_lines: int, blank_lines: int, characters: int, comment_tokens: int, string_tokens: int, number_tokens: int, keyword_tokens: int, identifier_tokens: int, operator_tokens: int)

Bases: object

Line- and token-level metrics for a source string.

Line counts are mutually exclusive: lines == code_lines + comment_lines + blank_lines. A line with both code and a trailing comment counts as a code line.

as_dict() dict
blank_lines: int
characters: int
code_lines: int
property comment_density: float

Fraction of non-blank lines that are comment-only.

comment_lines: int
property comment_to_code_ratio: float

Comment lines divided by code lines (0.0 when there is no code).

comment_tokens: int
identifier_tokens: int
keyword_tokens: int
lines: int
number_tokens: int
operator_tokens: int
string_tokens: int