Skip to content

[mypyc] Make some generated classes implicitly final #19235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypyc/irbuild/callable_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class for the nested function.
# Define the actual callable class ClassIR, and set its
# environment to point at the previously defined environment
# class.
callable_class_ir = ClassIR(name, builder.module_name, is_generated=True)
callable_class_ir = ClassIR(name, builder.module_name, is_generated=True, is_final_class=True)

# The functools @wraps decorator attempts to call setattr on
# nested functions, so we create a dict for these nested
Expand Down
5 changes: 4 additions & 1 deletion mypyc/irbuild/env_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class is generated, the function environment has not yet been
containing a nested function.
"""
env_class = ClassIR(
f"{builder.fn_info.namespaced_name()}_env", builder.module_name, is_generated=True
f"{builder.fn_info.namespaced_name()}_env",
builder.module_name,
is_generated=True,
is_final_class=True,
)
env_class.attributes[SELF_NAME] = RInstance(env_class)
if builder.fn_info.is_nested:
Expand Down
2 changes: 1 addition & 1 deletion mypyc/irbuild/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def instantiate_generator_class(builder: IRBuilder) -> Value:
def setup_generator_class(builder: IRBuilder) -> ClassIR:
name = f"{builder.fn_info.namespaced_name()}_gen"

generator_class_ir = ClassIR(name, builder.module_name, is_generated=True)
generator_class_ir = ClassIR(name, builder.module_name, is_generated=True, is_final_class=True)
if builder.fn_info.can_merge_generator_and_env_classes():
builder.fn_info.env_class = generator_class_ir
else:
Expand Down