Skip to content

Commit adf483b

Browse files
committed
Pass compiler options
1 parent 4d8b6e9 commit adf483b

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

mypyc/irbuild/prepare.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def build_type_map(
9595
for module, cdef in classes:
9696
with catch_errors(module.path, cdef.line):
9797
if mapper.type_to_ir[cdef.info].is_ext_class:
98-
prepare_class_def(module.path, module.fullname, cdef, errors, mapper)
98+
prepare_class_def(module.path, module.fullname, cdef, errors, mapper, options)
9999
else:
100100
prepare_non_ext_class_def(module.path, module.fullname, cdef, errors, mapper)
101101

@@ -110,7 +110,7 @@ def build_type_map(
110110
# is conditionally defined.
111111
for module in modules:
112112
for func in get_module_func_defs(module):
113-
prepare_func_def(module.fullname, None, func, mapper)
113+
prepare_func_def(module.fullname, None, func, mapper, options)
114114
# TODO: what else?
115115

116116
# Check for incompatible attribute definitions that were not
@@ -164,27 +164,28 @@ def get_module_func_defs(module: MypyFile) -> Iterable[FuncDef]:
164164

165165

166166
def prepare_func_def(
167-
module_name: str, class_name: str | None, fdef: FuncDef, mapper: Mapper
167+
module_name: str, class_name: str | None, fdef: FuncDef, mapper: Mapper, options: CompilerOptions
168168
) -> FuncDecl:
169169
kind = (
170170
FUNC_STATICMETHOD
171171
if fdef.is_static
172172
else (FUNC_CLASSMETHOD if fdef.is_class else FUNC_NORMAL)
173173
)
174-
decl = FuncDecl(fdef.name, class_name, module_name, mapper.fdef_to_sig(fdef, True), kind)
174+
sig = mapper.fdef_to_sig(fdef, options.strict_dunders_typing)
175+
decl = FuncDecl(fdef.name, class_name, module_name, sig, kind)
175176
mapper.func_to_decl[fdef] = decl
176177
return decl
177178

178179

179180
def prepare_method_def(
180-
ir: ClassIR, module_name: str, cdef: ClassDef, mapper: Mapper, node: FuncDef | Decorator
181+
ir: ClassIR, module_name: str, cdef: ClassDef, mapper: Mapper, node: FuncDef | Decorator, options: CompilerOptions
181182
) -> None:
182183
if isinstance(node, FuncDef):
183-
ir.method_decls[node.name] = prepare_func_def(module_name, cdef.name, node, mapper)
184+
ir.method_decls[node.name] = prepare_func_def(module_name, cdef.name, node, mapper, options)
184185
elif isinstance(node, Decorator):
185186
# TODO: do something about abstract methods here. Currently, they are handled just like
186187
# normal methods.
187-
decl = prepare_func_def(module_name, cdef.name, node.func, mapper)
188+
decl = prepare_func_def(module_name, cdef.name, node.func, mapper, options)
188189
if not node.decorators:
189190
ir.method_decls[node.name] = decl
190191
elif isinstance(node.decorators[0], MemberExpr) and node.decorators[0].name == "setter":
@@ -237,7 +238,7 @@ def can_subclass_builtin(builtin_base: str) -> bool:
237238

238239

239240
def prepare_class_def(
240-
path: str, module_name: str, cdef: ClassDef, errors: Errors, mapper: Mapper
241+
path: str, module_name: str, cdef: ClassDef, errors: Errors, mapper: Mapper, options: CompilerOptions
241242
) -> None:
242243
"""Populate the interface-level information in a class IR.
243244
@@ -304,7 +305,7 @@ def prepare_class_def(
304305
ir.mro = mro
305306
ir.base_mro = base_mro
306307

307-
prepare_methods_and_attributes(cdef, ir, path, module_name, errors, mapper)
308+
prepare_methods_and_attributes(cdef, ir, path, module_name, errors, mapper, options)
308309
prepare_init_method(cdef, ir, module_name, mapper)
309310

310311
for base in bases:
@@ -316,7 +317,7 @@ def prepare_class_def(
316317

317318

318319
def prepare_methods_and_attributes(
319-
cdef: ClassDef, ir: ClassIR, path: str, module_name: str, errors: Errors, mapper: Mapper
320+
cdef: ClassDef, ir: ClassIR, path: str, module_name: str, errors: Errors, mapper: Mapper, options: CompilerOptions
320321
) -> None:
321322
"""Populate attribute and method declarations."""
322323
info = cdef.info
@@ -338,20 +339,20 @@ def prepare_methods_and_attributes(
338339
add_setter_declaration(ir, name, attr_rtype, module_name)
339340
ir.attributes[name] = attr_rtype
340341
elif isinstance(node.node, (FuncDef, Decorator)):
341-
prepare_method_def(ir, module_name, cdef, mapper, node.node)
342+
prepare_method_def(ir, module_name, cdef, mapper, node.node, options)
342343
elif isinstance(node.node, OverloadedFuncDef):
343344
# Handle case for property with both a getter and a setter
344345
if node.node.is_property:
345346
if is_valid_multipart_property_def(node.node):
346347
for item in node.node.items:
347-
prepare_method_def(ir, module_name, cdef, mapper, item)
348+
prepare_method_def(ir, module_name, cdef, mapper, item, options)
348349
else:
349350
errors.error("Unsupported property decorator semantics", path, cdef.line)
350351

351352
# Handle case for regular function overload
352353
else:
353354
assert node.node.impl
354-
prepare_method_def(ir, module_name, cdef, mapper, node.node.impl)
355+
prepare_method_def(ir, module_name, cdef, mapper, node.node.impl, options)
355356

356357
if ir.builtin_base:
357358
ir.attributes.clear()
@@ -463,24 +464,24 @@ def prepare_init_method(cdef: ClassDef, ir: ClassIR, module_name: str, mapper: M
463464

464465

465466
def prepare_non_ext_class_def(
466-
path: str, module_name: str, cdef: ClassDef, errors: Errors, mapper: Mapper
467+
path: str, module_name: str, cdef: ClassDef, errors: Errors, mapper: Mapper, options: CompilerOptions
467468
) -> None:
468469
ir = mapper.type_to_ir[cdef.info]
469470
info = cdef.info
470471

471472
for node in info.names.values():
472473
if isinstance(node.node, (FuncDef, Decorator)):
473-
prepare_method_def(ir, module_name, cdef, mapper, node.node)
474+
prepare_method_def(ir, module_name, cdef, mapper, node.node, options)
474475
elif isinstance(node.node, OverloadedFuncDef):
475476
# Handle case for property with both a getter and a setter
476477
if node.node.is_property:
477478
if not is_valid_multipart_property_def(node.node):
478479
errors.error("Unsupported property decorator semantics", path, cdef.line)
479480
for item in node.node.items:
480-
prepare_method_def(ir, module_name, cdef, mapper, item)
481+
prepare_method_def(ir, module_name, cdef, mapper, item, options)
481482
# Handle case for regular function overload
482483
else:
483-
prepare_method_def(ir, module_name, cdef, mapper, get_func_def(node.node))
484+
prepare_method_def(ir, module_name, cdef, mapper, get_func_def(node.node), options)
484485

485486
if any(cls in mapper.type_to_ir and mapper.type_to_ir[cls].is_ext_class for cls in info.mro):
486487
errors.error(

0 commit comments

Comments
 (0)