Skip to content

Commit 5471267

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 67ce16a commit 5471267

18 files changed

+68
-44
lines changed

mypyc/analysis/attrdefined.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def foo(self) -> int:
9090
SetMem,
9191
Unreachable,
9292
)
93-
from mypyc.ir.rtypes import RInstance, RInstanceValue
93+
from mypyc.ir.rtypes import RInstance
9494

9595
# If True, print out all always-defined attributes of native classes (to aid
9696
# debugging and testing)

mypyc/codegen/emit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from mypyc.ir.ops import BasicBlock, Value
2424
from mypyc.ir.rtypes import (
2525
RInstance,
26+
RInstanceValue,
2627
RPrimitive,
2728
RTuple,
2829
RType,
@@ -49,7 +50,7 @@
4950
is_tuple_rprimitive,
5051
is_uint8_rprimitive,
5152
object_rprimitive,
52-
optional_value_type, RInstanceValue,
53+
optional_value_type,
5354
)
5455
from mypyc.namegen import NameGenerator, exported_name
5556
from mypyc.sametype import is_same_type
@@ -1069,7 +1070,9 @@ def emit_box(
10691070
setup_name = f"{name_prefix}_setup"
10701071
py_type_struct = self.type_struct_name(cl)
10711072
temp_dest = self.temp_name()
1072-
self.emit_line(f"{self.ctype_spaced(typ)}*{temp_dest} = ({self.ctype_spaced(typ)}*){setup_name}({py_type_struct});")
1073+
self.emit_line(
1074+
f"{self.ctype_spaced(typ)}*{temp_dest} = ({self.ctype_spaced(typ)}*){setup_name}({py_type_struct});"
1075+
)
10731076
self.emit_line(f"if (unlikely({temp_dest} == NULL))")
10741077
self.emit_line(" CPyError_OutOfMemory();")
10751078
for attr, attr_type in cl.attributes.items():

mypyc/codegen/emitfunc.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,28 @@
7171
)
7272
from mypyc.ir.pprint import generate_names_for_ir
7373
from mypyc.ir.rtypes import (
74-
c_pyssize_t_rprimitive,
74+
PyObject,
7575
RArray,
7676
RInstance,
77+
RInstanceValue,
7778
RStruct,
7879
RTuple,
7980
RType,
81+
c_pyssize_t_rprimitive,
8082
is_int32_rprimitive,
8183
is_int64_rprimitive,
8284
is_int_rprimitive,
8385
is_pointer_rprimitive,
8486
is_tagged,
85-
PyObject,
86-
RInstanceValue,
8787
)
8888

8989

9090
def struct_type(class_ir: ClassIR, emitter: Emitter) -> RStruct:
9191
"""Return the struct type for this instance type."""
92-
python_fields: list[tuple[str, RType]] = [("head", PyObject), ("vtable", c_pyssize_t_rprimitive)]
92+
python_fields: list[tuple[str, RType]] = [
93+
("head", PyObject),
94+
("vtable", c_pyssize_t_rprimitive),
95+
]
9396
class_fields = list(class_ir.attributes.items())
9497
attr_names = [emitter.attr(name) for name, _ in python_fields + class_fields]
9598
attr_types = [rtype for _, rtype in python_fields + class_fields]

mypyc/codegen/emitwrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
is_bool_rprimitive,
3535
is_int_rprimitive,
3636
is_object_rprimitive,
37-
object_rprimitive, RInstanceValue,
37+
object_rprimitive,
3838
)
3939
from mypyc.namegen import NameGenerator
4040

mypyc/ir/class_ir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from mypyc.common import PROPSET_PREFIX, JsonDict
88
from mypyc.ir.func_ir import FuncDecl, FuncIR, FuncSignature
99
from mypyc.ir.ops import DeserMaps, Value
10-
from mypyc.ir.rtypes import RInstance, RType, deserialize_type, RInstanceValue
10+
from mypyc.ir.rtypes import RInstance, RInstanceValue, RType, deserialize_type
1111
from mypyc.namegen import NameGenerator, exported_name
1212

1313
# Some notes on the vtable layout: Each concrete class has a vtable

mypyc/ir/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
object_rprimitive,
3636
pointer_rprimitive,
3737
short_int_rprimitive,
38-
void_rtype, RInstanceValue,
38+
void_rtype,
3939
)
4040

4141
if TYPE_CHECKING:

mypyc/ir/rtypes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
from abc import abstractmethod
2626
from typing import TYPE_CHECKING, ClassVar, Final, Generic, TypeVar
27-
2827
from typing_extensions import TypeGuard
2928

3029
from mypyc.common import IS_32_BIT_PLATFORM, PLATFORM_SIZE, JsonDict, short_name

mypyc/irbuild/builder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from contextlib import contextmanager
1717
from typing import Any, Callable, Final, Iterator, Sequence, Union
18-
1918
from typing_extensions import overload
2019

2120
from mypy.build import Graph
@@ -109,7 +108,7 @@
109108
is_tuple_rprimitive,
110109
none_rprimitive,
111110
object_rprimitive,
112-
str_rprimitive, RInstanceValue,
111+
str_rprimitive,
113112
)
114113
from mypyc.irbuild.context import FuncInfo, ImplicitClass
115114
from mypyc.irbuild.ll_builder import LowLevelIRBuilder

mypyc/irbuild/classdef.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
from __future__ import annotations
44

5+
import typing_extensions
56
from abc import abstractmethod
67
from typing import Callable, Final
78

8-
import typing_extensions
9-
109
from mypy.nodes import (
1110
TYPE_VAR_TUPLE_KIND,
1211
AssignmentStmt,
@@ -64,12 +63,7 @@
6463
handle_non_ext_method,
6564
load_type,
6665
)
67-
from mypyc.irbuild.util import (
68-
dataclass_type,
69-
get_func_def,
70-
is_constant,
71-
is_dataclass_decorator,
72-
)
66+
from mypyc.irbuild.util import dataclass_type, get_func_def, is_constant, is_dataclass_decorator
7367
from mypyc.primitives.dict_ops import dict_new_op, dict_set_item_op
7468
from mypyc.primitives.generic_ops import (
7569
iter_op,

mypyc/irbuild/function.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@
5454
Unreachable,
5555
Value,
5656
)
57-
from mypyc.ir.rtypes import (
58-
bool_rprimitive,
59-
dict_rprimitive,
60-
int_rprimitive,
61-
object_rprimitive,
62-
)
57+
from mypyc.ir.rtypes import bool_rprimitive, dict_rprimitive, int_rprimitive, object_rprimitive
6358
from mypyc.irbuild.builder import IRBuilder, SymbolTarget, gen_arg_defaults
6459
from mypyc.irbuild.callable_class import (
6560
add_call_to_callable_class,
@@ -91,7 +86,6 @@
9186
from mypyc.primitives.registry import builtin_names
9287
from mypyc.sametype import is_same_method_signature, is_same_type
9388

94-
9589
# Top-level transform functions
9690

9791

mypyc/irbuild/ll_builder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,9 @@ def dunder_op(self, lreg: Value, rreg: Value | None, op: str, line: int) -> Valu
14311431
if not is_binary and len(decl.sig.args) != 1:
14321432
return None
14331433

1434-
if is_binary and (len(decl.sig.args) != 2 or not is_subtype(rreg.type, decl.sig.args[1].type)):
1434+
if is_binary and (
1435+
len(decl.sig.args) != 2 or not is_subtype(rreg.type, decl.sig.args[1].type)
1436+
):
14351437
return None
14361438

14371439
if is_binary and is_subtype(not_implemented_op.type, decl.sig.ret_type):

mypyc/irbuild/prepare.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
get_mypyc_attrs,
5858
is_dataclass,
5959
is_extension_class,
60-
is_trait,
6160
is_immutable,
61+
is_trait,
6262
)
6363
from mypyc.options import CompilerOptions
6464
from mypyc.sametype import is_same_type
@@ -103,7 +103,9 @@ def build_type_map(
103103
if mapper.type_to_ir[cdef.info].is_ext_class:
104104
prepare_class_def(module.path, module.fullname, cdef, errors, mapper, options)
105105
else:
106-
prepare_non_ext_class_def(module.path, module.fullname, cdef, errors, mapper, options)
106+
prepare_non_ext_class_def(
107+
module.path, module.fullname, cdef, errors, mapper, options
108+
)
107109

108110
# Prepare implicit attribute accessors as needed if an attribute overrides a property.
109111
for module, cdef in classes:
@@ -170,7 +172,11 @@ def get_module_func_defs(module: MypyFile) -> Iterable[FuncDef]:
170172

171173

172174
def prepare_func_def(
173-
module_name: str, class_name: str | None, fdef: FuncDef, mapper: Mapper, options: CompilerOptions
175+
module_name: str,
176+
class_name: str | None,
177+
fdef: FuncDef,
178+
mapper: Mapper,
179+
options: CompilerOptions,
174180
) -> FuncDecl:
175181
kind = (
176182
FUNC_STATICMETHOD
@@ -184,10 +190,17 @@ def prepare_func_def(
184190

185191

186192
def prepare_method_def(
187-
ir: ClassIR, module_name: str, cdef: ClassDef, mapper: Mapper, node: FuncDef | Decorator, options: CompilerOptions
193+
ir: ClassIR,
194+
module_name: str,
195+
cdef: ClassDef,
196+
mapper: Mapper,
197+
node: FuncDef | Decorator,
198+
options: CompilerOptions,
188199
) -> None:
189200
if isinstance(node, FuncDef):
190-
ir.method_decls[node.name] = prepare_func_def(module_name, cdef.name, node, mapper, options)
201+
ir.method_decls[node.name] = prepare_func_def(
202+
module_name, cdef.name, node, mapper, options
203+
)
191204
elif isinstance(node, Decorator):
192205
# TODO: do something about abstract methods here. Currently, they are handled just like
193206
# normal methods.
@@ -244,7 +257,12 @@ def can_subclass_builtin(builtin_base: str) -> bool:
244257

245258

246259
def prepare_class_def(
247-
path: str, module_name: str, cdef: ClassDef, errors: Errors, mapper: Mapper, options: CompilerOptions
260+
path: str,
261+
module_name: str,
262+
cdef: ClassDef,
263+
errors: Errors,
264+
mapper: Mapper,
265+
options: CompilerOptions,
248266
) -> None:
249267
"""Populate the interface-level information in a class IR.
250268
@@ -323,7 +341,13 @@ def prepare_class_def(
323341

324342

325343
def prepare_methods_and_attributes(
326-
cdef: ClassDef, ir: ClassIR, path: str, module_name: str, errors: Errors, mapper: Mapper, options: CompilerOptions
344+
cdef: ClassDef,
345+
ir: ClassIR,
346+
path: str,
347+
module_name: str,
348+
errors: Errors,
349+
mapper: Mapper,
350+
options: CompilerOptions,
327351
) -> None:
328352
"""Populate attribute and method declarations."""
329353
info = cdef.info
@@ -470,7 +494,12 @@ def prepare_init_method(cdef: ClassDef, ir: ClassIR, module_name: str, mapper: M
470494

471495

472496
def prepare_non_ext_class_def(
473-
path: str, module_name: str, cdef: ClassDef, errors: Errors, mapper: Mapper, options: CompilerOptions
497+
path: str,
498+
module_name: str,
499+
cdef: ClassDef,
500+
errors: Errors,
501+
mapper: Mapper,
502+
options: CompilerOptions,
474503
) -> None:
475504
ir = mapper.type_to_ir[cdef.info]
476505
info = cdef.info

mypyc/irbuild/targets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from mypyc.ir.ops import Register, Value
4-
from mypyc.ir.rtypes import RInstance, RType, object_rprimitive, RInstanceValue
4+
from mypyc.ir.rtypes import RInstance, RType, object_rprimitive
55

66

77
class AssignmentTarget:

mypyc/irbuild/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def is_immutable(cdef: ClassDef) -> bool:
8787
"""Check if a class is immutable by checking if all its variables are marked as Final."""
8888
for v in cdef.info.names.values():
8989
if (
90-
isinstance(v.node, Var) and
91-
not v.node.is_classvar
90+
isinstance(v.node, Var)
91+
and not v.node.is_classvar
9292
and v.node.name not in ("__slots__", "__deletable__")
9393
):
9494
if not v.node.is_final or v.node.is_settable_property:

mypyc/rt_subtype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from mypyc.ir.rtypes import (
1919
RArray,
2020
RInstance,
21+
RInstanceValue,
2122
RPrimitive,
2223
RStruct,
2324
RTuple,
@@ -28,7 +29,7 @@
2829
is_bit_rprimitive,
2930
is_bool_rprimitive,
3031
is_int_rprimitive,
31-
is_short_int_rprimitive, RInstanceValue,
32+
is_short_int_rprimitive,
3233
)
3334
from mypyc.subtype import is_subtype
3435

mypyc/sametype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
from mypyc.ir.rtypes import (
77
RArray,
88
RInstance,
9+
RInstanceValue,
910
RPrimitive,
1011
RStruct,
1112
RTuple,
1213
RType,
1314
RTypeVisitor,
1415
RUnion,
15-
RVoid, RInstanceValue,
16+
RVoid,
1617
)
1718

1819

mypyc/subtype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from mypyc.ir.rtypes import (
66
RArray,
77
RInstance,
8+
RInstanceValue,
89
RPrimitive,
910
RStruct,
1011
RTuple,
@@ -20,7 +21,6 @@
2021
is_short_int_rprimitive,
2122
is_tagged,
2223
is_tuple_rprimitive,
23-
RInstanceValue,
2424
)
2525

2626

mypyc/transform/value_type_init.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
won't make the changes on the target object.
88
"""
99

10-
1110
from mypyc.ir.func_ir import FuncIR
1211
from mypyc.ir.rtypes import RInstance, RInstanceValue
1312
from mypyc.options import CompilerOptions

0 commit comments

Comments
 (0)