@@ -65,27 +65,6 @@ def __exit__(self, *args):
65
65
v .__set__ (self ._root , self .old_vals [k ])
66
66
67
67
68
- class _SectionRedirect :
69
- """Functions as a mock property on the PyTensorConfigParser.
70
-
71
- It redirects attribute access (to config subsectinos) to the
72
- new config variable properties that use "__" in their name.
73
- """
74
-
75
- def __init__ (self , root , section_name ):
76
- self ._root = root
77
- self ._section_name = section_name
78
- super ().__init__ ()
79
-
80
- def __getattr__ (self , attr ):
81
- warnings .warn (
82
- f"Accessing section '{ attr } ' through old .-based API. "
83
- f"This will be removed. Use 'config.{ self ._section_name } __{ attr } ' instead." ,
84
- DeprecationWarning ,
85
- )
86
- return getattr (self ._root , f"{ self ._section_name } __{ attr } " )
87
-
88
-
89
68
class PyTensorConfigParser :
90
69
"""Object that holds configuration settings."""
91
70
@@ -189,18 +168,6 @@ def add(self, name, doc, configparam, in_c_key=True):
189
168
# the ConfigParam implements __get__/__set__, enabling us to create a property:
190
169
setattr (self .__class__ , name , configparam )
191
170
192
- # The old API used dots for accessing a hierarchy of sections.
193
- # The following code adds redirects that spill DeprecationWarnings
194
- # while allowing backwards-compatible access to dot-based subsections.
195
- # Because the subsectioning is recursive, redirects must be added for
196
- # all levels. For example: ".test", ".test.subsection".
197
- sections = name .split ("__" )
198
- for s in range (1 , len (sections )):
199
- section_name = "__" .join (sections [:s ])
200
- if not hasattr (self , section_name ):
201
- redirect = _SectionRedirect (self , section_name )
202
- setattr (self .__class__ , section_name , redirect )
203
-
204
171
def fetch_val_for_key (self , key , delete_key = False ):
205
172
"""Return the overriding config value for a key.
206
173
A successful search returns a string value.
@@ -565,76 +532,3 @@ def _create_default_config():
565
532
pytensor_raw_cfg = pytensor_raw_cfg ,
566
533
)
567
534
return config
568
-
569
-
570
- class _ConfigProxy :
571
- """Like _SectionRedirect this class enables backwards-compatible access to the
572
- config settings, but raises DeprecationWarnings with instructions to use `pytensor.config`.
573
- """
574
-
575
- def __init__ (self , actual ):
576
- _ConfigProxy ._actual = actual
577
-
578
- def __getattr__ (self , attr ):
579
- if attr == "_actual" :
580
- return _ConfigProxy ._actual
581
- warnings .warn (
582
- "`pytensor.configparser.config` is deprecated; use `pytensor.config` instead." ,
583
- DeprecationWarning ,
584
- stacklevel = 2 ,
585
- )
586
- return getattr (self ._actual , attr )
587
-
588
- def __setattr__ (self , attr , value ):
589
- if attr == "_actual" :
590
- return setattr (_ConfigProxy ._actual , attr , value )
591
- warnings .warn (
592
- "`pytensor.configparser.config` is deprecated; use `pytensor.config` instead." ,
593
- DeprecationWarning ,
594
- stacklevel = 2 ,
595
- )
596
- return setattr (self ._actual , attr , value )
597
-
598
-
599
- # Create the actual instance of the config. This one should eventually move to
600
- # `configdefaults`:
601
- _config = _create_default_config ()
602
-
603
- # The old API often imported the default config object from `configparser`.
604
- # These imports/accesses should be replaced with `pytensor.config`, so this wraps
605
- # it with warnings:
606
- config = _ConfigProxy (_config )
607
-
608
- DEPRECATED_NAMES = [
609
- (
610
- "change_flags" ,
611
- "`change_flags` is deprecated; use `pytensor.config.change_flags` instead." ,
612
- _config .change_flags ,
613
- ),
614
- (
615
- "_change_flags" ,
616
- "`_change_flags` is deprecated; use `pytensor.config.change_flags` instead." ,
617
- _config .change_flags ,
618
- ),
619
- (
620
- "_config_print" ,
621
- "`_config_print` is deprecated; use `pytensor.config.config_print` instead." ,
622
- _config .config_print ,
623
- ),
624
- ]
625
-
626
-
627
- def __getattr__ (name ):
628
- """Intercept module-level attribute access of deprecated symbols.
629
-
630
- Adapted from https://stackoverflow.com/a/55139609/3006474.
631
-
632
- """
633
- from warnings import warn
634
-
635
- for old_name , msg , old_object in DEPRECATED_NAMES :
636
- if name == old_name :
637
- warn (msg , DeprecationWarning , stacklevel = 2 )
638
- return old_object
639
-
640
- raise AttributeError (f"module { __name__ } has no attribute { name } " )
0 commit comments