Commit a3ff798
Contributor
Add pickle support for Sentinel via singleton registry
Sentinel objects now support pickling/unpickling using a module-level
registry keyed by (module_name, name). Unpickled sentinels preserve
object identity (is checks pass).
Changes:
- Add _sentinel_registry dict for singleton tracking
- Convert __init__ to __new__ with registry-based singleton pattern
- Replace __getstate__ (which raised TypeError) with __reduce__
- __reduce__ returns (cls, (name, None, module_name)) for reconstruction
- Auto-detect calling module via inspect.currentframe()
- Update tests: verify pickle roundtrip, identity preservation, singleton
Implements the approach discussed in issue #720, following the PEP 661
reference implementation's singleton registry pattern.
Fixes #7201 parent 442d848 commit a3ff798
2 files changed
+43
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9570 | 9570 | | |
9571 | 9571 | | |
9572 | 9572 | | |
9573 | | - | |
| 9573 | + | |
9574 | 9574 | | |
9575 | | - | |
9576 | | - | |
9577 | | - | |
9578 | | - | |
9579 | | - | |
| 9575 | + | |
| 9576 | + | |
| 9577 | + | |
| 9578 | + | |
| 9579 | + | |
| 9580 | + | |
| 9581 | + | |
| 9582 | + | |
| 9583 | + | |
| 9584 | + | |
| 9585 | + | |
| 9586 | + | |
| 9587 | + | |
| 9588 | + | |
| 9589 | + | |
| 9590 | + | |
9580 | 9591 | | |
9581 | 9592 | | |
9582 | 9593 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
| |||
168 | 171 | | |
169 | 172 | | |
170 | 173 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
178 | 195 | | |
179 | 196 | | |
180 | 197 | | |
| |||
193 | 210 | | |
194 | 211 | | |
195 | 212 | | |
196 | | - | |
197 | | - | |
| 213 | + | |
| 214 | + | |
198 | 215 | | |
199 | 216 | | |
200 | 217 | | |
| |||
0 commit comments