-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11935a1
commit 5055357
Showing
2 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""The module contains tools for working with handlers.""" | ||
|
||
import functools | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from hammett.types import HANDLER_ASSIGNMENTS_TYPE, Func | ||
|
||
HANDLER_ASSIGNMENTS = (*functools.WRAPPER_ASSIGNMENTS, '__self__') | ||
|
||
|
||
def wraps_handler( | ||
wrapped: 'Func', | ||
assigned: 'HANDLER_ASSIGNMENTS_TYPE' = HANDLER_ASSIGNMENTS, | ||
updated: tuple[str] = functools.WRAPPER_UPDATES, | ||
) -> 'functools.partial[Func]': | ||
"""Identical to `functools.wraps`, the only thing different is the `assigned` argument. | ||
This is required for `calc_checksum` function to return a valid result even | ||
for a decorated handler. Should be used if a decorator for the handler is implemented. | ||
""" | ||
return functools.partial( | ||
functools.update_wrapper, | ||
wrapped=wrapped, | ||
assigned=assigned, | ||
updated=updated, | ||
) |