Skip to content

Commit 84db689

Browse files
committed
A few more comments about how the deprecations work
1 parent 1d221d1 commit 84db689

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

jax/_src/deprecations.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def deprecation_getattr(module, deprecations):
4747
def getattr(name):
4848
if name in deprecations:
4949
message, fn = deprecations[name]
50-
if fn is None:
50+
if fn is None: # Is the deprecation accelerated?
5151
raise AttributeError(message)
5252
warnings.warn(message, DeprecationWarning, stacklevel=2)
5353
return fn
@@ -57,11 +57,20 @@ def getattr(name):
5757

5858

5959
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+
"""
6165
message, _ = module._deprecations[name]
6266
module._deprecations[name] = (message, None)
6367

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.
6574
_registered_deprecations: dict[tuple[str, str], bool] = {}
6675

6776

0 commit comments

Comments
 (0)