@@ -88,12 +88,33 @@ class Options:
8888 """Options collected from flags."""
8989
9090 def __init__ (self ) -> None :
91+ self ._initialize_caches ()
92+ self ._initialize_build_options ()
93+ self ._initialize_disallow_options ()
94+ self ._initialize_warning_and_reporting_options ()
95+ self ._initialize_misc_behavior ()
96+ self ._initialize_error_code_controls ()
97+ self ._initialize_target_definitions ()
98+ self ._initialize_caching_options ()
99+ self ._initialize_integration_flags ()
100+ self ._initialize_development_options ()
101+ self ._initialize_test_options ()
102+ self ._initialize_experimental_options ()
103+
104+ def _initialize_caches (self ) -> None :
91105 # Cache for clone_for_module()
92106 self ._per_module_cache : dict [str , Options ] | None = None
93107
108+ # Per-module options (raw)
109+ self .per_module_options : dict [str , dict [str , object ]] = {}
110+ self ._glob_options : list [tuple [str , Pattern [str ]]] = []
111+ self .unused_configs : set [str ] = set ()
112+
113+ def _initialize_build_options (self ) -> None :
94114 # -- build options --
95115 self .build_type = BuildType .STANDARD
96116 self .python_version : tuple [int , int ] = sys .version_info [:2 ]
117+
97118 # The executable used to search for PEP 561 packages. If this is None,
98119 # then mypy does not search for PEP 561 packages.
99120 self .python_executable : str | None = sys .executable
@@ -108,37 +129,46 @@ def __init__(self) -> None:
108129
109130 self .custom_typing_module : str | None = None
110131 self .custom_typeshed_dir : str | None = None
132+
111133 # The abspath() version of the above, we compute it once as an optimization.
112134 self .abs_custom_typeshed_dir : str | None = None
113135 self .mypy_path : list [str ] = []
114136 self .report_dirs : dict [str , str ] = {}
137+
115138 # Show errors in PEP 561 packages/site-packages modules
116139 self .no_silence_site_packages = False
117140 self .no_site_packages = False
118141 self .ignore_missing_imports = False
142+
119143 # Is ignore_missing_imports set in a per-module section
120144 self .ignore_missing_imports_per_module = False
145+
121146 # Typecheck modules without stubs or py.typed marker
122147 self .follow_untyped_imports = False
123148 self .follow_imports = "normal" # normal|silent|skip|error
149+
124150 # Whether to respect the follow_imports setting even for stub files.
125151 # Intended to be used for disabling specific stubs.
126152 self .follow_imports_for_stubs = False
153+
127154 # PEP 420 namespace packages
128155 # This allows definitions of packages without __init__.py and allows packages to span
129156 # multiple directories. This flag affects both import discovery and the association of
130157 # input files/modules/packages to the relevant file and fully qualified module name.
131158 self .namespace_packages = True
159+
132160 # Use current directory and MYPYPATH to determine fully qualified module names of files
133161 # passed by automatically considering their subdirectories as packages. This is only
134162 # relevant if namespace packages are enabled, since otherwise examining __init__.py's is
135163 # sufficient to determine module names for files. As a possible alternative, add a single
136164 # top-level __init__.py to your packages.
137165 self .explicit_package_bases = False
166+
138167 # File names, directory names or subpaths to avoid checking
139168 self .exclude : list [str ] = []
140169 self .exclude_gitignore : bool = False
141170
171+ def _initialize_disallow_options (self ) -> None :
142172 # disallow_any options
143173 self .disallow_any_generics = False
144174 self .disallow_any_unimported = False
@@ -168,6 +198,7 @@ def __init__(self) -> None:
168198 # Disallow subclassing values of type 'Any'
169199 self .disallow_subclassing_any = False
170200
201+ def _initialize_warning_and_reporting_options (self ) -> None :
171202 # Also check typeshed for missing annotations
172203 self .warn_incomplete_stub = False
173204
@@ -194,6 +225,7 @@ def __init__(self) -> None:
194225 # Warn about unused '[mypy-<pattern>]' or '[[tool.mypy.overrides]]' config sections
195226 self .warn_unused_configs = False
196227
228+ def _initialize_misc_behavior (self ) -> None :
197229 # Files in which to ignore all non-fatal errors
198230 self .ignore_errors = False
199231
@@ -241,6 +273,7 @@ def __init__(self) -> None:
241273 # type analysis.
242274 self .warn_unreachable = False
243275
276+ def _initialize_error_code_controls (self ) -> None :
244277 # Variable names considered True
245278 self .always_true : list [str ] = []
246279
@@ -255,6 +288,7 @@ def __init__(self) -> None:
255288 self .enable_error_code : list [str ] = []
256289 self .enabled_error_codes : set [ErrorCode ] = set ()
257290
291+ def _initialize_target_definitions (self ) -> None :
258292 # Use script name instead of __main__
259293 self .scripts_are_modules = False
260294
@@ -281,6 +315,7 @@ def __init__(self) -> None:
281315
282316 self .junit_format : str = "global" # global|per_file
283317
318+ def _initialize_caching_options (self ) -> None :
284319 # Caching and incremental checking options
285320 self .incremental = True
286321 self .cache_dir = defaults .CACHE_DIR
@@ -293,10 +328,10 @@ def __init__(self) -> None:
293328 self .cache_fine_grained = False
294329 # Read cache files in fine-grained incremental mode (cache must include dependencies)
295330 self .use_fine_grained_cache = False
296-
297331 # Run tree.serialize() even if cache generation is disabled
298332 self .debug_serialize = False
299333
334+ def _initialize_integration_flags (self ) -> None :
300335 # Tune certain behaviors when being used as a front-end to mypyc. Set per-module
301336 # in modules being compiled. Not in the config file or command line.
302337 self .mypyc = False
@@ -321,11 +356,7 @@ def __init__(self) -> None:
321356 # Paths of user plugins
322357 self .plugins : list [str ] = []
323358
324- # Per-module options (raw)
325- self .per_module_options : dict [str , dict [str , object ]] = {}
326- self ._glob_options : list [tuple [str , Pattern [str ]]] = []
327- self .unused_configs : set [str ] = set ()
328-
359+ def _initialize_development_options (self ) -> None :
329360 # -- development options --
330361 self .verbosity = 0 # More verbose messages (for troubleshooting)
331362 self .pdb = False
@@ -338,6 +369,7 @@ def __init__(self) -> None:
338369 self .timing_stats : str | None = None
339370 self .line_checking_stats : str | None = None
340371
372+ def _initialize_test_options (self ) -> None :
341373 # -- test options --
342374 # Stop after the semantic analysis phase
343375 self .semantic_analysis_only = False
@@ -349,6 +381,7 @@ def __init__(self) -> None:
349381 # Use this sparingly to avoid tests diverging from non-test behavior.
350382 self .test_env = False
351383
384+ def _initialize_experimental_options (self ) -> None :
352385 # -- experimental options --
353386 self .shadow_file : list [list [str ]] | None = None
354387 self .show_column_numbers : bool = False
@@ -408,6 +441,7 @@ def __init__(self) -> None:
408441
409442 # Output html file for mypyc -a
410443 self .mypyc_annotation_file : str | None = None
444+
411445 # Skip writing C output files, but perform all other steps of a build (allows
412446 # preserving manual tweaks to generated C file)
413447 self .mypyc_skip_c_generation = False
0 commit comments