-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Open
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-multiprocessingtype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
Description
Feature or enhancement
Proposal:
Currently, the multiprocessing.heap
module validates requested memory sizes in two different places:
Heap.malloc()
BufferWrapper.__init__()
Both duplicate the same logic:
if size < 0:
raise ValueError("Size {0:n} out of range".format(size))
if sys.maxsize <= size:
raise OverflowError("Size {0:n} too large".format(size))
Proposed Change
Move this logic into a private static method (Heap._validate_size).
Benefits
- Removes duplication and ensures consistency.
- Improves maintainability (future changes affect only one place).
- Binds
sys.maxsize
at definition time (_maxsize=sys.maxsize
) to avoid repeated global lookups.
Impact
- No behavior changes. This change does not alter functionality or the external API of multiprocessing. It only removes duplication and ensures future modifications to size validation remain consistent.
- Existing
multiprocessing
tests already cover these code paths.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-multiprocessingtype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)