Skip to content

Refactor: extract logic in Options.__init__ into helper methods #19011

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

victorletichevsky
Copy link

This pull request contributes to issue #5917, which encourages the decomposition of overly long methods to improve code clarity and maintainability.

Summary of changes

Refactored Options.__init__ by extracting its logic into several private helper methods:

  • _initialize_caches
  • _initialize_build_options
  • _initialize_disallow_options
  • _initialize_warning_and_reporting_options
  • _initialize_misc_behavior
  • _initialize_error_code_controls
  • _initialize_target_definitions
  • _initialize_caching_options
  • _initialize_integration_flags
  • _initialize_development_options
  • _initialize_test_options
  • _initialize_experimental_options

Notes

  • All logic remains unchanged.
  • Original comments have been preserved and relocated appropriately.

This is a pure refactor in line with issue #5917.

Copy link
Contributor

github-actions bot commented May 1, 2025

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A long __init__ method that initializes attributes is arguably one case where splitting into multiple methods is not desirable, since our informal convention is to define all attributes in __init__. In the future we might even introduce a check to generate an error if an attribute is defined outside __init__ or the class body.

Defining attributes in the class body is not a good workaround either, since then we'd have declarations and initializations far away from each other, which is again not ideal. So unfortunately this is probably one of the few long methods where splitting it up doesn't seem worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants