Skip to content

Commit ae9242a

Browse files
committed
style: autorefactor whole project
1 parent 6c62a57 commit ae9242a

20 files changed

+32
-26
lines changed

libdestruct/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# Licensed under the MIT license. See LICENSE file in the project root for details.
55
#
66

7-
try: # pragma: no cover
7+
try: # pragma: no cover
88
from rich.traceback import install
99

1010
install()
11-
except ImportError: # pragma: no cover
11+
except ImportError: # pragma: no cover
1212
pass
1313

1414
from libdestruct.c import c_int, c_long, c_str, c_uint, c_ulong

libdestruct/backing/memory_resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from libdestruct.backing.resolver import Resolver
1212

13-
if TYPE_CHECKING: # pragma: no cover
13+
if TYPE_CHECKING: # pragma: no cover
1414
from collections.abc import MutableSequence
1515

1616

libdestruct/c/struct_parser.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
TYPEDEFS = {}
2929
"""A cache for parsed type definitions, indexed by name."""
3030

31+
3132
def definition_to_type(definition: str) -> type[obj]:
3233
"""Converts a C struct definition to a struct object."""
3334
parser = c_parser.CParser()
@@ -39,7 +40,9 @@ def definition_to_type(definition: str) -> type[obj]:
3940
try:
4041
ast = parser.parse(definition)
4142
except c_parser.ParseError as e:
42-
raise ValueError("Invalid definition. Please add the necessary includes if using non-standard type definitions.") from e
43+
raise ValueError(
44+
"Invalid definition. Please add the necessary includes if using non-standard type definitions."
45+
) from e
4346

4447
# We assume that the root declaration is the last one.
4548
root = ast.ext[-1].type
@@ -122,7 +125,11 @@ def arr_to_type(arr: c_ast.ArrayDecl) -> type[obj]:
122125

123126
def type_decl_to_type(decl: c_ast.TypeDecl, parent: c_ast.Struct | None = None) -> type[obj]:
124127
"""Converts a C type declaration to a type."""
125-
if not isinstance(decl, c_ast.TypeDecl) and not isinstance(decl, c_ast.PtrDecl) and not isinstance(decl, c_ast.ArrayDecl):
128+
if (
129+
not isinstance(decl, c_ast.TypeDecl)
130+
and not isinstance(decl, c_ast.PtrDecl)
131+
and not isinstance(decl, c_ast.ArrayDecl)
132+
):
126133
raise TypeError("Definition must be a type declaration.")
127134

128135
if isinstance(decl, c_ast.PtrDecl):
@@ -158,7 +165,7 @@ def to_uniform_name(name: str) -> str:
158165
"""Converts a name to a uniform name."""
159166
name = name.replace("unsigned", "u")
160167
name = name.replace("_Bool", "bool")
161-
name = name.replace("uchar", "ubyte") # uchar is not a valid ctypes type
168+
name = name.replace("uchar", "ubyte") # uchar is not a valid ctypes type
162169

163170
# We have to convert each intX, uintX, intX_t, uintX_t to the original char, short etc.
164171
name = name.replace("uint8_t", "ubyte")
@@ -184,15 +191,15 @@ def expand_includes(definition: str) -> str:
184191
f.write(definition)
185192
f.flush()
186193

187-
result = subprocess.run(["cc", "-std=c99", "-E", f.name], capture_output=True, text=True, check=True) # noqa: S607
194+
result = subprocess.run(["cc", "-std=c99", "-E", f.name], capture_output=True, text=True, check=True) # noqa: S607
188195

189196
return result.stdout
190197

191198

192199
def cleanup_attributes(definition: str) -> str:
193200
"""Cleans up attributes in a C definition."""
194201
# Remove __attribute__ ((...)) from the definition.
195-
pattern = r"__attribute__\s*\(\((?:[^()]+|\((?:[^()]+|\([^()]*\))*\))*\)\)" # ChatGPT provided this, don't ask me
202+
pattern = r"__attribute__\s*\(\((?:[^()]+|\((?:[^()]+|\([^()]*\))*\))*\)\)" # ChatGPT provided this, don't ask me
196203
return re.sub(pattern, "", definition)
197204

198205

libdestruct/common/array/array_field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from libdestruct.common.array import array
1313
from libdestruct.common.field import Field
1414

15-
if TYPE_CHECKING: # pragma: no cover
15+
if TYPE_CHECKING: # pragma: no cover
1616
from libdestruct.backing.resolver import Resolver
1717
from libdestruct.common.obj import obj
1818

libdestruct/common/array/array_field_inflater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from libdestruct.common.array.linear_array_field import LinearArrayField
1313
from libdestruct.common.type_registry import TypeRegistry
1414

15-
if TYPE_CHECKING: # pragma: no cover
15+
if TYPE_CHECKING: # pragma: no cover
1616
from collections.abc import Callable
1717

1818
from libdestruct.backing.resolver import Resolver

libdestruct/common/array/array_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from libdestruct.common.struct.struct import struct
1313
from libdestruct.common.utils import size_of
1414

15-
if TYPE_CHECKING: # pragma: no cover
15+
if TYPE_CHECKING: # pragma: no cover
1616
from collections.abc import Generator
1717

1818
from libdestruct.backing.resolver import Resolver

libdestruct/common/array/array_of.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from libdestruct.common.array.linear_array_field import LinearArrayField
1212

13-
if TYPE_CHECKING: # pragma: no cover
13+
if TYPE_CHECKING: # pragma: no cover
1414
from libdestruct.common.array.array_field import ArrayField
1515
from libdestruct.common.obj import obj
1616

libdestruct/common/enum/enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from libdestruct.common.obj import obj
1212
from libdestruct.common.type_registry import TypeRegistry
1313

14-
if TYPE_CHECKING: # pragma: no cover
14+
if TYPE_CHECKING: # pragma: no cover
1515
from enum import Enum
1616

1717
from libdestruct.backing.resolver import Resolver

libdestruct/common/enum/enum_field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from libdestruct.common.enum import enum
1313
from libdestruct.common.field import Field
1414

15-
if TYPE_CHECKING: # pragma: no cover
15+
if TYPE_CHECKING: # pragma: no cover
1616
from libdestruct.backing.resolver import Resolver
1717
from libdestruct.common.obj import obj
1818

libdestruct/common/enum/enum_field_inflater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from libdestruct.common.enum.int_enum_field import IntEnumField
1212
from libdestruct.common.type_registry import TypeRegistry
1313

14-
if TYPE_CHECKING: # pragma: no cover
14+
if TYPE_CHECKING: # pragma: no cover
1515
from collections.abc import Callable
1616

1717
from libdestruct.backing.resolver import Resolver

0 commit comments

Comments
 (0)