Coverage for metrics / halstead / python.py: 100%
7 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
1"""Halstead complexity measures for Python."""
3from __future__ import annotations
5from metrics.halstead.common import make_compute_halstead
7_PY_OPERATOR_TOKENS = {
8 # Arithmetic
9 "+",
10 "-",
11 "*",
12 "/",
13 "//",
14 "%",
15 "**",
16 # Comparison
17 "==",
18 "!=",
19 "<",
20 ">",
21 "<=",
22 ">=",
23 # Bitwise
24 "&",
25 "|",
26 "^",
27 "~",
28 "<<",
29 ">>",
30 # Assignment
31 "=",
32 "+=",
33 "-=",
34 "*=",
35 "/=",
36 "//=",
37 "%=",
38 "**=",
39 "&=",
40 "|=",
41 "^=",
42 "<<=",
43 ">>=",
44 # Other symbols
45 ".",
46 ",",
47 ":",
48 ";",
49 "(",
50 ")",
51 "[",
52 "]",
53 "{",
54 "}",
55 "->",
56}
58_PY_KEYWORD_OPERATORS = {
59 "if_statement",
60 "elif_clause",
61 "else_clause",
62 "for_statement",
63 "while_statement",
64 "return_statement",
65 "yield",
66 "function_definition",
67 "class_definition",
68 "import_statement",
69 "import_from_statement",
70 "try_statement",
71 "except_clause",
72 "finally_clause",
73 "with_statement",
74 "raise_statement",
75 "assert_statement",
76 "pass_statement",
77 "break_statement",
78 "continue_statement",
79 "delete_statement",
80 "global_statement",
81 "nonlocal_statement",
82 "match_statement",
83 "case_clause",
84 "lambda",
85}
87_PY_OPERAND_TYPES = {
88 "identifier",
89 "integer",
90 "float",
91 "string",
92 "concatenated_string",
93 "true",
94 "false",
95 "none",
96}
98_PY_COMMENT_TYPES = {"comment"}
101compute_halstead_py = make_compute_halstead(
102 _PY_COMMENT_TYPES, _PY_KEYWORD_OPERATORS, _PY_OPERAND_TYPES, _PY_OPERATOR_TOKENS
103)