Skip to content

Commit 96216d4

Browse files
committed
Consistently use Dataclass syntac for AssignmentInfo and related classes
1 parent 028d9c2 commit 96216d4

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

pythonbpf/vmlinux_parser/assignment_info.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from enum import Enum, auto
2-
from typing import Any, Dict, List, Optional, TypedDict
2+
from typing import Any, Dict, List, Optional
33
from dataclasses import dataclass
44
import llvmlite.ir as ir
55

66
from pythonbpf.vmlinux_parser.dependency_node import Field
77

88

9-
@dataclass
109
class AssignmentType(Enum):
1110
CONSTANT = auto()
1211
STRUCT = auto()
@@ -16,15 +15,15 @@ class AssignmentType(Enum):
1615

1716

1817
@dataclass
19-
class FunctionSignature(TypedDict):
18+
class FunctionSignature:
2019
return_type: str
2120
param_types: List[str]
2221
varargs: bool
2322

2423

2524
# Thew name of the assignment will be in the dict that uses this class
2625
@dataclass
27-
class AssignmentInfo(TypedDict):
26+
class AssignmentInfo:
2827
value_type: AssignmentType
2928
python_type: type
3029
value: Optional[Any]

pythonbpf/vmlinux_parser/vmlinux_exports_handler.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,38 @@ def is_vmlinux_enum(self, name):
3737
"""Check if name is a vmlinux enum constant"""
3838
return (
3939
name in self.vmlinux_symtab
40-
and self.vmlinux_symtab[name]["value_type"] == AssignmentType.CONSTANT
40+
and self.vmlinux_symtab[name].value_type == AssignmentType.CONSTANT
4141
)
4242

4343
def get_vmlinux_struct_type(self, name):
4444
"""Check if name is a vmlinux struct type"""
4545
if (
4646
name in self.vmlinux_symtab
47-
and self.vmlinux_symtab[name]["value_type"] == AssignmentType.STRUCT
47+
and self.vmlinux_symtab[name].value_type == AssignmentType.STRUCT
4848
):
49-
return self.vmlinux_symtab[name]["python_type"]
49+
return self.vmlinux_symtab[name].python_type
5050
else:
5151
raise ValueError(f"{name} is not a vmlinux struct type")
5252

5353
def is_vmlinux_struct(self, name):
5454
"""Check if name is a vmlinux struct"""
5555
return (
5656
name in self.vmlinux_symtab
57-
and self.vmlinux_symtab[name]["value_type"] == AssignmentType.STRUCT
57+
and self.vmlinux_symtab[name].value_type == AssignmentType.STRUCT
5858
)
5959

6060
def handle_vmlinux_enum(self, name):
6161
"""Handle vmlinux enum constants by returning LLVM IR constants"""
6262
if self.is_vmlinux_enum(name):
63-
value = self.vmlinux_symtab[name]["value"]
63+
value = self.vmlinux_symtab[name].value
6464
logger.info(f"Resolving vmlinux enum {name} = {value}")
6565
return ir.Constant(ir.IntType(64), value), ir.IntType(64)
6666
return None
6767

6868
def get_vmlinux_enum_value(self, name):
6969
"""Handle vmlinux enum constants by returning LLVM IR constants"""
7070
if self.is_vmlinux_enum(name):
71-
value = self.vmlinux_symtab[name]["value"]
71+
value = self.vmlinux_symtab[name].value
7272
logger.info(f"The value of vmlinux enum {name} = {value}")
7373
return value
7474
return None
@@ -115,16 +115,16 @@ def handle_vmlinux_struct_field(
115115
def has_field(self, struct_name, field_name):
116116
"""Check if a vmlinux struct has a specific field"""
117117
if self.is_vmlinux_struct(struct_name):
118-
python_type = self.vmlinux_symtab[struct_name]["python_type"]
118+
python_type = self.vmlinux_symtab[struct_name].python_type
119119
return hasattr(python_type, field_name)
120120
return False
121121

122122
def get_field_type(self, vmlinux_struct_name, field_name):
123123
"""Get the type of a field in a vmlinux struct"""
124124
if self.is_vmlinux_struct(vmlinux_struct_name):
125-
python_type = self.vmlinux_symtab[vmlinux_struct_name]["python_type"]
125+
python_type = self.vmlinux_symtab[vmlinux_struct_name].python_type
126126
if hasattr(python_type, field_name):
127-
return self.vmlinux_symtab[vmlinux_struct_name]["members"][field_name]
127+
return self.vmlinux_symtab[vmlinux_struct_name].members[field_name]
128128
else:
129129
raise ValueError(
130130
f"Field {field_name} not found in vmlinux struct {vmlinux_struct_name}"
@@ -135,10 +135,10 @@ def get_field_type(self, vmlinux_struct_name, field_name):
135135
def get_field_index(self, vmlinux_struct_name, field_name):
136136
"""Get the type of a field in a vmlinux struct"""
137137
if self.is_vmlinux_struct(vmlinux_struct_name):
138-
python_type = self.vmlinux_symtab[vmlinux_struct_name]["python_type"]
138+
python_type = self.vmlinux_symtab[vmlinux_struct_name].python_type
139139
if hasattr(python_type, field_name):
140140
return list(
141-
self.vmlinux_symtab[vmlinux_struct_name]["members"].keys()
141+
self.vmlinux_symtab[vmlinux_struct_name].members.keys()
142142
).index(field_name)
143143
else:
144144
raise ValueError(

0 commit comments

Comments
 (0)