mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Merge pull request #15 from pythonbpf/static-type-checks
Static type checks
This commit is contained in:
3
.github/workflows/format.yml
vendored
3
.github/workflows/format.yml
vendored
@ -5,10 +5,7 @@ name: Format
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
pull_request:
|
|
||||||
push:
|
push:
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre-commit:
|
pre-commit:
|
||||||
|
|||||||
@ -41,16 +41,15 @@ repos:
|
|||||||
- id: ruff
|
- id: ruff
|
||||||
args: ["--fix", "--show-fixes"]
|
args: ["--fix", "--show-fixes"]
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
exclude: ^(docs)
|
exclude: ^(docs)|^(tests)|^(examples)
|
||||||
|
|
||||||
## Checking static types
|
# Checking static types
|
||||||
#- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
# rev: "v1.10.0"
|
rev: "v1.10.0"
|
||||||
# hooks:
|
hooks:
|
||||||
# - id: mypy
|
- id: mypy
|
||||||
# files: "setup.py"
|
exclude: ^(tests)|^(examples)
|
||||||
# args: []
|
additional_dependencies: [types-setuptools]
|
||||||
# additional_dependencies: [types-setuptools]
|
|
||||||
|
|
||||||
# Changes tabs to spaces
|
# Changes tabs to spaces
|
||||||
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
||||||
|
|||||||
@ -141,7 +141,7 @@ def compile() -> bool:
|
|||||||
success = True
|
success = True
|
||||||
success = compile_to_ir(str(caller_file), str(ll_file)) and success
|
success = compile_to_ir(str(caller_file), str(ll_file)) and success
|
||||||
|
|
||||||
success = (
|
success = bool(
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
"llc",
|
"llc",
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
from llvmlite import ir
|
from llvmlite import ir
|
||||||
import ast
|
import ast
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from .helper import HelperHandlerRegistry, handle_helper_call
|
from .helper import HelperHandlerRegistry, handle_helper_call
|
||||||
from .type_deducer import ctypes_to_ir
|
from .type_deducer import ctypes_to_ir
|
||||||
from .binary_ops import handle_binary_op
|
from .binary_ops import handle_binary_op
|
||||||
from .expr_pass import eval_expr, handle_expr
|
from .expr_pass import eval_expr, handle_expr
|
||||||
|
|
||||||
local_var_metadata = {}
|
local_var_metadata: dict[str | Any, Any] = {}
|
||||||
|
|
||||||
|
|
||||||
def get_probe_string(func_node):
|
def get_probe_string(func_node):
|
||||||
@ -656,9 +656,9 @@ def infer_return_type(func_node: ast.FunctionDef):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return type(e).__name__
|
return type(e).__name__
|
||||||
|
|
||||||
for node in ast.walk(func_node):
|
for walked_node in ast.walk(func_node):
|
||||||
if isinstance(node, ast.Return):
|
if isinstance(walked_node, ast.Return):
|
||||||
t = _expr_type(node.value)
|
t = _expr_type(walked_node.value)
|
||||||
if found_type is None:
|
if found_type is None:
|
||||||
found_type = t
|
found_type = t
|
||||||
elif found_type != t:
|
elif found_type != t:
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class MapProcessorRegistry:
|
class MapProcessorRegistry:
|
||||||
"""Registry for map processor functions"""
|
"""Registry for map processor functions"""
|
||||||
|
|
||||||
_processors = {}
|
_processors: dict[str, Callable[..., Any]] = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def register(cls, map_type_name):
|
def register(cls, map_type_name):
|
||||||
|
|||||||
Reference in New Issue
Block a user