@@ -62,7 +62,7 @@ class Options:
62
62
63
63
def __init__ (self ) -> None :
64
64
# Cache for clone_for_module()
65
- self .per_module_cache = None # type: Optional[Dict[str, Options]]
65
+ self ._per_module_cache = None # type: Optional[Dict[str, Options]]
66
66
67
67
# -- build options --
68
68
self .build_type = BuildType .STANDARD
@@ -222,7 +222,7 @@ def __init__(self) -> None:
222
222
223
223
# Per-module options (raw)
224
224
self .per_module_options = OrderedDict () # type: OrderedDict[str, Dict[str, object]]
225
- self .glob_options = [] # type: List[Tuple[str, Pattern[str]]]
225
+ self ._glob_options = [] # type: List[Tuple[str, Pattern[str]]]
226
226
self .unused_configs = set () # type: Set[str]
227
227
228
228
# -- development options --
@@ -280,7 +280,8 @@ def snapshot(self) -> object:
280
280
for k in get_class_descriptors (Options ):
281
281
if hasattr (self , k ) and k != "new_semantic_analyzer" :
282
282
d [k ] = getattr (self , k )
283
- del d ['per_module_cache' ]
283
+ # Remove private attributes from snapshot
284
+ d = {k : v for k , v in d .items () if not k .startswith ('_' )}
284
285
return d
285
286
286
287
def __repr__ (self ) -> str :
@@ -295,7 +296,7 @@ def apply_changes(self, changes: Dict[str, object]) -> 'Options':
295
296
return new_options
296
297
297
298
def build_per_module_cache (self ) -> None :
298
- self .per_module_cache = {}
299
+ self ._per_module_cache = {}
299
300
300
301
# Config precedence is as follows:
301
302
# 1. Concrete section names: foo.bar.baz
@@ -320,7 +321,7 @@ def build_per_module_cache(self) -> None:
320
321
concrete = [k for k in structured_keys if not k .endswith ('.*' )]
321
322
322
323
for glob in unstructured_glob_keys :
323
- self .glob_options .append ((glob , self .compile_glob (glob )))
324
+ self ._glob_options .append ((glob , self .compile_glob (glob )))
324
325
325
326
# We (for ease of implementation) treat unstructured glob
326
327
# sections as used if any real modules use them or if any
@@ -333,7 +334,7 @@ def build_per_module_cache(self) -> None:
333
334
# on inheriting from parent configs.
334
335
options = self .clone_for_module (key )
335
336
# And then update it with its per-module options.
336
- self .per_module_cache [key ] = options .apply_changes (self .per_module_options [key ])
337
+ self ._per_module_cache [key ] = options .apply_changes (self .per_module_options [key ])
337
338
338
339
# Add the more structured sections into unused configs, since
339
340
# they only count as used if actually used by a real module.
@@ -345,14 +346,14 @@ def clone_for_module(self, module: str) -> 'Options':
345
346
NOTE: Once this method is called all Options objects should be
346
347
considered read-only, else the caching might be incorrect.
347
348
"""
348
- if self .per_module_cache is None :
349
+ if self ._per_module_cache is None :
349
350
self .build_per_module_cache ()
350
- assert self .per_module_cache is not None
351
+ assert self ._per_module_cache is not None
351
352
352
353
# If the module just directly has a config entry, use it.
353
- if module in self .per_module_cache :
354
+ if module in self ._per_module_cache :
354
355
self .unused_configs .discard (module )
355
- return self .per_module_cache [module ]
356
+ return self ._per_module_cache [module ]
356
357
357
358
# If not, search for glob paths at all the parents. So if we are looking for
358
359
# options for foo.bar.baz, we search foo.bar.baz.*, foo.bar.*, foo.*,
@@ -363,15 +364,15 @@ def clone_for_module(self, module: str) -> 'Options':
363
364
path = module .split ('.' )
364
365
for i in range (len (path ), 0 , - 1 ):
365
366
key = '.' .join (path [:i ] + ['*' ])
366
- if key in self .per_module_cache :
367
+ if key in self ._per_module_cache :
367
368
self .unused_configs .discard (key )
368
- options = self .per_module_cache [key ]
369
+ options = self ._per_module_cache [key ]
369
370
break
370
371
371
372
# OK and *now* we need to look for unstructured glob matches.
372
373
# We only do this for concrete modules, not structured wildcards.
373
374
if not module .endswith ('.*' ):
374
- for key , pattern in self .glob_options :
375
+ for key , pattern in self ._glob_options :
375
376
if pattern .match (module ):
376
377
self .unused_configs .discard (key )
377
378
options = options .apply_changes (self .per_module_options [key ])
0 commit comments