@@ -47,7 +47,7 @@ def deprecation_getattr(module, deprecations):
47
47
def getattr (name ):
48
48
if name in deprecations :
49
49
message , fn = deprecations [name ]
50
- if fn is None :
50
+ if fn is None : # Is the deprecation accelerated?
51
51
raise AttributeError (message )
52
52
warnings .warn (message , DeprecationWarning , stacklevel = 2 )
53
53
return fn
@@ -57,11 +57,20 @@ def getattr(name):
57
57
58
58
59
59
def accelerate_module_deprecation (module : ModuleType , name : str ) -> None :
60
- """Accelerate the deprecation of a module-level attribute"""
60
+ """Accelerate the deprecation of a module-level attribute.
61
+
62
+ Raises an AttributeError instead of a DeprecationWarning upon attribute access.
63
+ Used in Google-internal code to implement faster deprecation.
64
+ """
61
65
message , _ = module ._deprecations [name ]
62
66
module ._deprecations [name ] = (message , None )
63
67
64
-
68
+ # The following mechanism is a separate one, for registering and
69
+ # accelerating deprecations that are not imports (for example, deprecations
70
+ # of a function argument).
71
+ # Maps a pair of strings to a boolean specifying whether the deprecation
72
+ # is accelerated. The intent is that non-accelerated deprecations will warn,
73
+ # and accelerated deprecations will error.
65
74
_registered_deprecations : dict [tuple [str , str ], bool ] = {}
66
75
67
76
0 commit comments