Add a common mixin class for handling invalidation.
Review Request #15170 — Created July 15, 2026 and updated
Sensitive data (keys, secrets) are intended to be invalidated early,
keeping the data safe and out of memory as best as possible.This class implements this as a mixin class. It handles invalidation
when the instance falls out of scope, and allows the object to be used
as a context manager, invalidating on exit.
Unit tests pass.
| Summary | ID |
|---|---|
| 7545462ea83693d7a39ab6c19687196949dfcf3d |
| Description | From | Last Updated |
|---|---|---|
|
Instead of methods that raise NotImplementedError, how about subclassing abc.ABC and marking those with @abstractmethod? |
|
|
|
Should probably change this to say self? |
|
|
|
__exit__ never gets called with kwargs. Can we use the standard signature? def __exit( self, exc_type: type[BaseException] | None, exc_value: … |
|
|
|
If a subclass raises an exception from __init__, __del__ could get called on a partially-constructed instance. If the implementation of … |
|
|
|
It's harmless here, but just to model goot behavior, can we call super().__init__()? |
|
|
|
Since this is greenfield, can we use pytest test cases and real docstrings instead of a UnitTest subclass? |
|
|
|
typo: exceptio -> exception |
|
|
|
This was copy/pasted without updating to match the test. |
|
- Change Summary:
-
Removed the changes to
BaseKey. Changing the order of commits. - Commits:
-
Summary ID e713456079169d085dbd89d8a9e54ae804b475cf 7545462ea83693d7a39ab6c19687196949dfcf3d
Checks run (2 succeeded)
-
-
Instead of methods that raise
NotImplementedError, how about subclassingabc.ABCand marking those with@abstractmethod? -
-
__exit__never gets called with kwargs. Can we use the standard signature?def __exit( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None, ) -> None: -
If a subclass raises an exception from
__init__,__del__could get called on a partially-constructed instance. If the implementation ofinvalidate()then assumes an attribute it set, it willAttributeError, and python will silently swallow it (I think it prints to stderr, but that's not the best for a library). This could leave the object not fully invalidated.Can we document in here that the implementation must be able to handle partially-constructed instances, and cannot assume that all attributes have been set?
We also should document that this method needs to be idempotent, since it can get called first from
__exit__and then again from__del__ -
-
Since this is greenfield, can we use pytest test cases and real docstrings instead of a UnitTest subclass?
-
-