Skip to content

Commit 429f514

Browse files
Merge pull request #15 from pythonbpf/static-type-checks
Static type checks
2 parents 59b3d65 + c92272d commit 429f514

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

.github/workflows/format.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ name: Format
55

66
on:
77
workflow_dispatch:
8-
pull_request:
98
push:
10-
branches:
11-
- master
129

1310
jobs:
1411
pre-commit:

.pre-commit-config.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,15 @@ repos:
4141
- id: ruff
4242
args: ["--fix", "--show-fixes"]
4343
- id: ruff-format
44-
exclude: ^(docs)
44+
exclude: ^(docs)|^(tests)|^(examples)
4545

46-
## Checking static types
47-
#- repo: https://github.com/pre-commit/mirrors-mypy
48-
# rev: "v1.10.0"
49-
# hooks:
50-
# - id: mypy
51-
# files: "setup.py"
52-
# args: []
53-
# additional_dependencies: [types-setuptools]
46+
# Checking static types
47+
- repo: https://github.com/pre-commit/mirrors-mypy
48+
rev: "v1.10.0"
49+
hooks:
50+
- id: mypy
51+
exclude: ^(tests)|^(examples)
52+
additional_dependencies: [types-setuptools]
5453

5554
# Changes tabs to spaces
5655
- repo: https://github.com/Lucas-C/pre-commit-hooks

pythonbpf/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def compile() -> bool:
141141
success = True
142142
success = compile_to_ir(str(caller_file), str(ll_file)) and success
143143

144-
success = (
144+
success = bool(
145145
subprocess.run(
146146
[
147147
"llc",

pythonbpf/functions_pass.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from llvmlite import ir
22
import ast
3-
3+
from typing import Any
44

55
from .helper import HelperHandlerRegistry, handle_helper_call
66
from .type_deducer import ctypes_to_ir
77
from .binary_ops import handle_binary_op
88
from .expr_pass import eval_expr, handle_expr
99

10-
local_var_metadata = {}
10+
local_var_metadata: dict[str | Any, Any] = {}
1111

1212

1313
def get_probe_string(func_node):
@@ -656,9 +656,9 @@ def _expr_type(e):
656656
except Exception:
657657
return type(e).__name__
658658

659-
for node in ast.walk(func_node):
660-
if isinstance(node, ast.Return):
661-
t = _expr_type(node.value)
659+
for walked_node in ast.walk(func_node):
660+
if isinstance(walked_node, ast.Return):
661+
t = _expr_type(walked_node.value)
662662
if found_type is None:
663663
found_type = t
664664
elif found_type != t:

pythonbpf/maps/maps_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from collections.abc import Callable
2+
from typing import Any
3+
4+
15
class MapProcessorRegistry:
26
"""Registry for map processor functions"""
37

4-
_processors = {}
8+
_processors: dict[str, Callable[..., Any]] = {}
59

610
@classmethod
711
def register(cls, map_type_name):

0 commit comments

Comments
 (0)